Copy link to clipboard
Copied
Hi there
I'm working with EasyCatalog. And i'm after a little script which could populate all my empty cells (dozens of tables in my ID document) with a "-".
I saw this threat : https://community.adobe.com/t5/indesign/assign-cell-style-to-empty-table-cells-clear-cell-style-over... which is quite similar
A little help would be very usefull because i just don't know how to script it 🙂
Thank you very much
Best regards
Miran
var myDocument = app.documents.item(0);
var allCells = myDocument.stories.everyItem().tables.everyItem().cells.everyItem().getElements();
for ( var i = 0; i < allCells.length; i++)
{
if ( allCells[i].contents === '')
{
allCells[i].contents = '-';
}
}
Copy link to clipboard
Copied
var myDocument = app.documents.item(0);
var allCells = myDocument.stories.everyItem().tables.everyItem().cells.everyItem().getElements();
for ( var i = 0; i < allCells.length; i++)
{
if ( allCells[i].contents === '')
{
allCells[i].contents = '-';
}
}
Copy link to clipboard
Copied
Hi brianp311
I thank you very much! That's it! It works like a charm
Is there a possibility to try the opposite thing : find columns with only "-" in it and delete them...
Copy link to clipboard
Copied
Sure. But even though you know nothing of scripting, take a look at the code and think about how you might reverse it...
var myDocument = app.documents.item(0);
var allCells = myDocument.stories.everyItem().tables.everyItem().cells.everyItem().getElements();
for ( var i = 0; i < allCells.length; i++)
{
if ( allCells[i].contents === '' )
{
allCells[i].contents = '-';
}
else if ( allCells[i].contents === '-' ) {
allCells[i].contents = '';
}
}
Copy link to clipboard
Copied
So i guess that the beginning is not so difficult :
var myDocument = app.documents.item(0);
var allCells = myDocument.stories.everyItem().tables.everyItem().cells.everyItem().getElements();
for ( var i = 0; i < allCells.length; i++)
{
if ( allCells[i].contents === '-' )
{
but after that how could i ask ID to delete every column which contains cells with only "-"
Copy link to clipboard
Copied
Oh I see, I thought you just wanted to convert cells with "-" to "" (the solution of which I posted). What you're after is a bit tougher. Try this, though you may run into issues if you have merged cells in your tables.
var myDocument = app.documents.item(0);
var allCols = myDocument.stories.everyItem().tables.everyItem().columns.everyItem().getElements();
var allCells, isAllHyphens;
for ( var i = allCols.length-1; i >= 0; i--)
{
isAllHyphens = true;
allCells = allCols[i].cells.everyItem().getElements();
for (var j = 0; j < allCells.length; j++) {
if (allCells[j].contents !== "-") {
isAllHyphens = false;
break;
}
}
if (isAllHyphens) { allCols[i].remove(); }
}
Copy link to clipboard
Copied
Goodmorning Brian p311
Oh thank you very much!
It works very well.