I am trying to delete empty rows in tables throughout a module. My code is below:
// Look for empty rows in tables
for obj in current Module do
{
Object ro, ce, cellRef
bool blank
// Look for tables
if(table(obj))
{
// If a table is found, look at each row
for ro in table(obj) do
{
// Look at each cell in the row
blank = true
for ce in row(ro) do
{
// If the current cell has text, set blank to false
if(ce."Object Text" "" != "")
{
blank = false
}
else
{
cellRef = ce
}
}
// If blank is still true, the row is empty so we can delete it
if(blank)
{
deleteRow(cellRef)
}
}
}
}
My question is simple...what am I doing wrong here? it seems to me like it should work, and the script DOES run, but nothing seems to be different in the module. If you can help me, I would really appreciate it! Thanks! CMusicFan - Mon Mar 31 11:24:45 EDT 2014 |
Re: Deleting empty table rows Usually it is not a good idea to delete something inside a loop that is using it. So instead of deleting a row when looping through the rows, save it in a skip list and when you all down with the table, then deleted the rows in the skip list. Hope this helps, Greg |
Re: Deleting empty table rows GregM_dxler - Mon Mar 31 12:00:55 EDT 2014 Usually it is not a good idea to delete something inside a loop that is using it. So instead of deleting a row when looping through the rows, save it in a skip list and when you all down with the table, then deleted the rows in the skip list. Hope this helps, Greg That's a fair point. I had not considered that. I'll give it a shot and post how it turns out. Thanks |
Re: Deleting empty table rows To find table objects use "for o in document current Module do"
|
Re: Deleting empty table rows Tony_Goodman - Tue Apr 01 05:02:06 EDT 2014 To find table objects use "for o in document current Module do"
Thank you both for your help! I have been able to get my script working. Here it is in full:
// Search for empty table rows
Skip rowsToDelete = create
for o in document DocumentModule do
{
Object ro, ce, cellRef
bool rowIsEmpty
// Look for tables
if(table(o))
{
// If a table is found, look at each row
for ro in table(o) do
{
// Initialize rowIsEmpty
rowIsEmpty = true
// Look at each cell in the row
for ce in row(ro) do
{
// If the current cell has text, set blank to false
if(ce."Object Text" "" != "")
{
rowIsEmpty = false
break
}
}
if(rowIsEmpty)
{
put(rowsToDelete, number(ce), ce)
}
}
}
// Increment the progress bar and the count variable
progressStep ++count
// Halt the script if the cancel button is pressed
if (progressCancelled) HaltScript
}
// Delete the rows
for o in rowsToDelete do
{
deleteRow o
}
delete(rowsToDelete)
|