Hi there
I`m new to scripting, and but i can figure there`s a way of doing this.
A lot`s of table need to have rows with merged cells.
If the first cell contains text, then the other 5 don`t, then another cell with text and so on.
I need to test how many cells are empty after the filled one, so i can merge them, then move to the next and do the same!
Any help please,
thank you
No need to work backwards here ![]()
What I said:
Going left to right over a row,
if you encounter a cell with contents,
move right while seeing cells with contents.
If that cell is empty,
merge with the previous cell (which may or may already be merged, we don't care);
repeat until coming to a cell with contents.
Repeat until you come to the end of the row.
It looks like this in Javascript (you didn't mention your language preference, so this is what you are getting):
table = app.selection[0];
if (!(table instanceof Table)) table = table.parent;
if (table instanceof Cell) table = table.parent;
if (table instanceof Table)
{
for (r=0; r<table.rows.length; r++)
{
c = 0;
while (c < table.rows[r].cells.length)
{
while (c < table.rows[r].cells.length &&
table.rows[r].cells[c].contents.length > 0)
c++;
while (c < table.rows[r].cells.length &&
table.rows[r].cells[c].contents.length == 0)
table.rows[r].cells[c].merge (table.rows[r].cells[c-1]);
}
}
}
Finally made it:
for (var i = 0; i < myTable.rows[0].cells.length; i++) {
for (var j = i; j < myTable.rows[0].cells.length-1; j++) {
if (myTable.rows[0].cells[j+1].contents != "" || myTable.rows[0].cells[j+1].overflows) {
break;
}
}
if (i < j) {
myTable.rows[0].cells[i].merge(myTable.rows[0].cells[j]);
}
}
not another question comes: is there a way to split a table with 20 rows in 4 tables let`s say 5 rows each?
javascripting, of course!
Thank everyone for the clues!
North America
Europe, Middle East and Africa
Asia Pacific