Copy link to clipboard
Copied
This script fills empty cells of a table with a certain character (e.g. -).
It now affects the entire document.
Would anyone like to help modify it by adding the options: whole document, current article, current selection?
Thanks a lot.
var myDocument = app.documents.item(0);
var myStory = myDocument.stories;
for (var s=0; s<myStory.length;s++){
var myTable = myStory.item(s).tables;
for (var t=0; t<myTable.length;t++)
for (var i=0; i<myTable[t].columns.length; i++){
for (var j=0; j<myTable[t].columns.item(i).cells.length; j++){
if (myTable[t].columns.item(i).cells.item(j).contents == ""){
myTable[t].columns.item(i).cells.item(j).contents ="—"; //The character you want to fill
}
}
}
}
Copy link to clipboard
Copied
For a single selection the story can be accessed using the following code.
app.selection[0].parentStory
You can modify your code accordingly, in this case you don't need the loop as there is only a single story
-Manan
Copy link to clipboard
Copied
The internal two loops - as you are going through all cells anyway - you can just loop through the cells of the Table:
for (var j=0; j<myTable[t].cells.length; j++)
{
if (myTable[t].cells.item(j).contents == "")
{
myTable[t].cells.item(j).contents ="—"; //The character you want to fill
}
}
Copy link to clipboard
Copied
Okay, thanks a lot, I'll try it sometime.