Code to be evaluated! [012] Extract the Table Title! …
Hi Scripters,
Table Titles are included in the first row of each table and I want to "extract" them before the table using a para style "Title" applied to them!
Before:

After:

I've written the code below. Even if it totally works well, I'm not sure [as usual!] it's the more beautiful code we can read!
Thanks for your comments! ![]()
app.doScript("main()", ScriptLanguage.javascript, undefined, UndoModes.ENTIRE_SCRIPT, "Extract Title! …");
function main()
{
var
myDoc = app.activeDocument,
myTables = myDoc.stories.everyItem().tables.everyItem().getElements();
for ( var T = 0 ; T < myTables.length; T++ )
{
myTables
.storyOffset.paragraphs[0].duplicate(LocationOptions.after, myTables .storyOffset.paragraphs[0]); var myRows = myTables
.rows; var R = myRows.length;
while ( R -- ) if (R != 0) myRows
.remove(); var myTitle = myTables
.convertToText("\t", "\r"); myTitle.appliedParagraphStyle = "Title";
}
myTables = myDoc.stories.everyItem().tables.everyItem().getElements();
var T = myTables.length;
while ( T-- ) myTables
.rows[0].remove();
}
(^/)
