Skip to main content
MoshiMan
Participant
January 23, 2014
Question

Exporting data in tables to an Excel spreadsheet?

  • January 23, 2014
  • 3 replies
  • 21698 views

Is there a script or another way to export or save a documents tables (multiple tables over several pages) to an excel spreadsheet? I have found a solution which involves exporting each spread as a html file which i can then open straight in excel but this is still quite long winded and i can only seem to do this a spread at a time. As the job I am working on involves many pages this is taking too long. Surely there must be a script which can automate this in some way. I am fairly new to scripting so any help will be grateful. I have searched in scripting but nothing has really come close to what i am trying to achieve. Indesign CS5.5 user.

This topic has been closed for replies.

3 replies

Participant
August 19, 2015

Hi

I have two computers. This script was working on one computer but not the other but now the computer it was working on is coming up with this error (picture below).

I have a 30 page document. Table data on each page. I need to extract each table from every page into 1 excel file. Can anyone help me.

Trevor:
Legend
August 19, 2015

Weird message!

Try the following.

Delete lines 57 and 58 (as per your error message)

app.doScript (myAppleScript, ScriptLanguage.APPLESCRIPT_LANGUAGE); 

// alert (myAppleScript); exit() for Debug

Add theses lines in their place

var w = new Window('dialog'),

  e = w.add('edittext', undefined, myAppleScript, {multiline: true, readonly: true});

e.characters = 120;

w.show();

exit();


Save the script as Exports SIMPLE tables as a proper excel file DEBUG.jsx

Run the script and your get some window like this

Copy the contents and paste it into the applescript editor.

Run the applescript from the applescript editor and you can see what message comes up.

You can post the applescript that you pasted in the applescript editor over here and a screenshot of the message you get.

Maybe someone will be able to help you.

HTH

Trevor

Vamitul
Legend
August 19, 2015

Hi Trev,

Before sending the cell's contents to applescript make sure you encode the special characters in it. Claired97144388 probably has some quotes inside the table's cells and those screw up your as script. I learned that one the hard way

Daniel Sterchi
Inspiring
February 3, 2014

Hi Matthew

As Harbs wrote, convert the table to text, then store the text as CSV-File

To convert the Table to text:

- Table.convertToText (columnSeparator: string , rowSeparator: string ): Text

Save the text to a file:

- Text.exportFile (format:varies, to: File , showingOptions: Boolean , using: PDFExportPreset , versionComments: string , forceSave: Boolean )

That could or should work

Kind regards

Daniel (from Switzerland)

Community Expert
February 3, 2014

@Daniel – ahem(!)…

The documentation does say so, but "using:PDFExportPreset" implies a PDF file as output file format. This parameter is not provided, if you want to export to a text file format, let's look at

Enumeration ExportFormat

ExportFormat.EPS_TYPEExports to EPS format.1952400720 = 't_EP'
ExportFormat.EPUBExports to EPub format.1701868898 = 'epub'
ExportFormat.HTMLExports to XHTML format.1213484364 = 'HTML'
ExportFormat.INCOPY_MARKUPExports to InCopy markup (ICML) format.1768123756 = 'icml'
ExportFormat.INDESIGN_MARKUPExports to InDesign markup (IDML) format.1768189292 = 'idml'
ExportFormat.INDESIGN_SNIPPETExports to InDesign snippet (IDMS) format.1936617588 = 'snpt'
ExportFormat.INTERACTIVE_PDFExports to Interactive PDF format.1952409936 = 't_iP'
ExportFormat.JPGExports to JPEG format.1246775072 = 'JPG '
ExportFormat.PACKAGED_XFLExports to packaged XFL format.1702389356 = 'exfl'
ExportFormat.PDF_TYPEExports to PDF format.1952403524 = 't_PD'
ExportFormat.PNG_FORMATExports to PNG format.1699761735 = 'ePNG'
ExportFormat.RTFExports to rich text format (RTF).1381254688 = 'RTF '
ExportFormat.SWFExports to SWF format.1702066022 = 'eswf'
ExportFormat.TAGGED_TEXTExports to a tagged text file with a TXT extension.1416066168 = 'Tgtx'
ExportFormat.TEXT_TYPEExports to text (TXT) format.1952412773 = 't_te'
ExportFormat.XMLExports the document's tagged content to XML.1481460768 = 'XML '

Two of that list will meet our needs*:

ExportFormat.RTF

ExportFormat.TEXT_TYPE

*And these two types only support a tabular approach with *formatted* text and *formatted* table cells in a unsufficient way.

@Matthew:

There is another way:

simply copy/paste to Excel.

Or even better copy/paste to Word.

And in another step copy/paste from Word to Excel.

And see, if some of the formatting will survive.

Here an example with a very simple InDesign table:

1. Original InDesign table

2a. Copy/Paste that table to Word:

2b. Copy/paste to Excel:

3. Here the extra step. Copy/paste from Word (2a) to Excel:

But remember: this is a very simple table. Prepare for surprises if it's going more complex.

Used software: InDesign CS5.5, MS Excel 2004, MS Word 2004 on OSX 10.6.8.

When on a Mac these steps could be automated with AppleScript. On a Windows PC, I think, VB Script could do that. But here I'm not sure, because I hardly know AppleScript and to a even lesser extend VB Script.

Uwe

MoshiMan
MoshiManAuthor
Participant
February 4, 2014

Thanks Laubender. I think the ExportFormat.RTF would work as the tables are set up as tab seperated coulmns. I ideally need to select all table in the document at once, convert to text and then export to RFT format.

I have started with this to select the contents of the tables:

app.activeDocument.stories.everyItem().tables.everyItem()

But as for the rest I haven't managed to work out how to follow on with this:

Table.convertToText (columnSeparator: string , rowSeparator: string ): Text

Any suggestions...?

Harbs.
Legend
January 27, 2014

The simplest solution is probably to save the table contents as a csv files and open that in Excel.