JavaScript InDesign - Slow to delete table rows / How to delete multiple table rows at once
Hi,
I wrote a function that deletes empty table rows, but for some reason it works very slowly. When 180 rows have to be deleted, it takes 21 seconds to do so. Considering I have two such tables and many data merged documents, it rather adds up.
I was wondering if someone knows why it is this slow. We thought that perhaps we could make it faster by deleting a range of rows at once rather than deleting rows one by one, but I don't know how to delete multiple rows at once.
Here is the code:
function delRows(doc){
// If the tables' rows' contents are 0 in length (i.e. empty), delete the rows
var myRowsApp1 = doc.textFrames.itemByName("Appendix1").tables[0].rows.everyItem().getElements();
for(var i = myRowsApp1.length - 1; i >= 0; i--)
{
var rowContent = myRowsApp1[i].contents;
rowContent.shift();
if(rowContent.toString().replace(/,/g,"").replace(/\uFEFF/g,"").length != 0){
myRowsApp1[i].remove();
}
}
var myRowsApp2 = doc.textFrames.itemByName("Appendix2").tables[0].rows.everyItem().getElements();
for(var i = myRowsApp2.length - 1; i >= 0; i--)
{
var rowContent = myRowsApp2[i].contents;
rowContent.shift();
if(rowContent.toString().replace(/,/g,"").replace(/\uFEFF/g,"").length == 0){
myRowsApp2[i].remove();
}
}
}
Cheers,
Heidi
