Skip to main content
Known Participant
May 19, 2009
Question

[CS3]How to export a table in InDesign to an excel file?

  • May 19, 2009
  • 2 replies
  • 2193 views

Hi,

Can any one tell me how to script the process of exporting a table to excel file in InDesign CS3 using javascript?

Thanks in advance.

myRiaz

This topic has been closed for replies.

2 replies

Inspiring
May 19, 2009

Sorry, no javaScript, but here are some lines from a localization tool that I made in VB. I simply loop through the Rows and Columns and use the Excel DOM to fill the Excel-cells.

Of course you can read amended/localized Excel files back into inDesign the same way, provided that the tables match (nr of rows and columns).

Afterwards you could loop through the characters of each cell to apply the formatting that you want to keep in Excel, such as SuperScripts.

Hope it helps you.

Set myExcel = CreateObject("Excel.Application")

myExcel.Visible = True
Set myTableBook = myExcel.Workbooks.Add
Set myTableSheet = myTableBook.Worksheets.Item(1)

myTableSheet.Columns.ColumnWidth = 35
myTableSheet.Cells.VerticalAlignment = xlVAlignTop
myTableSheet.Cells.WrapText = True

For R = 1 To myTable.Rows.Count
    Set myTableRow = myTable.Rows.Item(R)
    For C = 1 To myTableRow.Cells.Count
        Set myTableCell = myTableRow.Cells.Item(C)
        If Len(myTableCell.Contents) = 0 Then
            myTableSheet.Cells(R, C) = ""
        Else
            myTableSheet.Cells(R, C) = myTableCell.Contents
            myTableSheet.Cells(R, C).Value = Replace(myTableSheet.Cells(R, C).Value, "1397058884", "—")
            myTableSheet.Cells(R, C).Value = Replace(myTableSheet.Cells(R, C).Value, Chr(13), Chr(10))
        End If
    Next C
Next R

good luck

TonyT

Peter Kahrel
Community Expert
Community Expert
May 19, 2009

In the object-model viewer, look under the convertToText () method of tables:

myTable.convertToText ("\t", "\r");

converts the table to text, with tabs as column separators and returns as line separators. Then import the table in Excel.

Peter