In my indesign document i have around 250 pages, each of which contain 1 table (1 per page). What i am trying to do is:
- Get the value of the top row of each table
- Retrieve the first letter of the cell contents
- create a textframe on each page to output that letter
Here is my code so far:
var doc = app.activeDocument;
var myTable = app.activeDocument.stories.everyItem().tables.everyItem().getElements();
alert(myTable.length)//no. of tables in a document
for(var i=0; i<myTable.length; i++) {
var textFrame = doc.pages[0].textFrames.add();
var string = myTable[i].contents;
textFrame.properties =
{
geometricBounds : [ 0,0,100,100 ],
strokeWidth : 0,
fillColor : "None",
contents : string
};
}
As this is a glossary, the letters will be A,B,C,D..
For example, table 1 the first row contains the string "Another", so on this page a textframe on the top left corner will say the letter A
UPDATE: Get the first letter from each table
var myTable = app.activeDocument.stories.everyItem().tables.everyItem().getElements();
alert(myTable.length)//no. of tables in a document
for(var i=0; i<myTable.length; i++)
{
var string = myTable[i].contents[0][0];
alert(string);
}