write contents of table to a text file
I have a need to export the tables from all the documents of a book. It would be nice to also increment a counter so that the number of each table also gets exported along with the text. I have tried _.write() as well as _.exportFile(). The _.write() creates the files but they are empty and the _.exportFile() approach throws a "no a function" error. Here are the two versions. Note: I don't run both at the same time. I just include them here to make for easier commenting. I suspect I am failing to address the proper constructor type or something. Any help would be very much appreciated.
var myDoc = app.activeDocument;
var myTables = myDoc.stories.everyItem().tables.everyItem().getElements();
var fname = app.activeDocument.name;
for (var d=0; d<myTables.length; d++)
{
var a = new File("~/Documents/table"+
+".txt"); var b = myTables
.contents; var d = b.join("\r");
a.open("w");
a.write(d);
a.close();
d.exportFile(ExportFormat.TEXT_TYPE, a, false);
}
