The following script should remove any empty rows in all tables in a document:
EDIT: From prior experience, I know it's a better idea to count backwards when deleting, so here is the earlier script with the order reversed:
var myDocument = app.activeDocument;
for(var i=myDocument.textFrames.length-1; i>=0; i--){
for(var j=myDocument.textFrames[i].tables.length-1; j>=0; j--){
for(var k=myDocument.textFrames[i].tables[j].rows.length-1; k>=0; k--){
myContents = 0;
for(var l=myDocument.textFrames[i].tables[j].rows[k].cells.length-1; l>=0; l--){
if (myDocument.textFrames[i].tables[j].rows[k].cells[l].contents != "") myContents++;
}
if (myContents == 0) myDocument.textFrames[i].tables[j].rows[k].remove();
}
}
}
Jongware has probably answered this already, but if not:
To run a script in InDesign, copy the code and paste it into
an ordinary text editor (such as Notepad in Windows), then
save the file with the extension .jsx in the Scripts Panel Folder
(typical path: Start > MyComputer > Local Disk(C:) >
Program Files > Adobe > Adobe InDesign CS3 > Scripts >
Scripts Panel).
It will then be available from within InDesign (Window > Automation > Scripts).
Yesterday's script removes empty rows from all tables in a document.
You might find the script below a bit more convenient, as it removes
empty rows in selected tables (or tables in selected text) only.
To run the script, highlight a table or some text containing a
number of tables, and then double-click on the name of the script in
the Scripts panel.
var mySelection=app.activeDocument.selection[0];
try{ var myTableCount = mySelection.tables.length;}
catch(myError){ var myTableCount = 1;}
for (var i=myTableCount-1; i >=0; i--) {
try{ var myTable = mySelection.tables.item(i);}
catch(myError){var myTable = mySelection; }
for(var j=myTable.rows.length-1; j>=0; j--){
var myContents = 0;
for(var k=myTable.rows[j].cells.length-1; k>=0; k--){
if (myTable.rows[j].cells[k].contents != "") myContents++;
}
if (myContents == 0) myTable.rows[j].remove();
}
}
I got this to work except that it considered rows that had a column with too wide of text as empty (i.e. there is a date 03/12/11 in a column too wide to hold it, therefore it shows up as a red dot). I need to keep those rows. How would you modify this script to be cautious of that?
Thank you,
Tim
Sure. The script currently increments a variable called "myContents" if there are non-zero contents in the cell:
if (myTable.rows[j].cells[k].contents != "") myContents++;
And then if myContents is zero, it removes the cell.
So you could also increment myContents if the text is overset; just add a line like this after the above:
if (myTable.rows[j].cells[k].overflows) myContents++;
North America
Europe, Middle East and Africa
Asia Pacific