Automatically convert first rows of Excel files to header rows in Adobe InDesign

InDesign is evolving for sure. But there are still things which drive me crazy. Like the problem that a placed (and linkes) Excel file will lose it’s header row (meaning after the link update the first row is a normal body row). One has to reconvert the first rows to header rows each time you update the Excel file link.
Of course you can work-around this nifty „bug“ by just give the first row another formatting. But if you depend on functions like repeating header rows for long tables spanning over several pages this doesn’t work.
Even in InDesign CS6 this problem isn’t fixed. So we have to help ourselves: use script automation to fix the problem.

The script just gets all tables in your document and sets the first row type as header row. Thus, the next step would be to attach an update event handler onto the Excel file links (but this didn’t work for me, tonight. An extension of the script will follow 😉 )

So here is the script code. Save it as .jsx file in your InDesign script folder (on a Mac it could be /Users/YOURUSERNAME/Library/Preferences/Adobe InDesign/Version 7.0/en_US/Scripts/Scripts Panel) and run it after every update of your Excel file.

var myTables = app.activeDocument.stories.everyItem().tables;

for (var i = 0; i < myTables.length; i++) {
    myTables[i].rows.firstItem().rowType = RowTypes.HEADER_ROW;

Hope this works for you. Feel free to add your questions and feedback in the comments section below.

Remark: This should work with all InDesign versions starting at CS5.

3 Kommentare

  1. Mario
    | Permalink

    Hi Mike, i think that indesign (CS6) 8.01 fix the problem of the update (header remain header). The problem is before: indd table style do not recognizes the header row that i set in excel and in table styles.

    Your script report an error: 45 (Error string: Object is invalid). Line 4.
    Do you have an idea to solve this? Very useful can be also convert table for page (not all tables of the document).
    Your script can be very useful immediately after placing an excel file for convert to header the first row.

    See also this old thread:

    Many thanks.

    • Mike Battistella
      | Permalink

      Hi Mario,

      thanks for your comment. Maybe you could provide me the InDesign file (in a CS5 compatible version, like IDML) on which the script fails? So I can have a look at it.


  2. Mario
    | Permalink

    Mike! Really many thanks!
    Sure! Please send me your mail (i use CS6 but i send you an idml)!

Einen Kommentar hinterlassen

Ihre E-Mail wird niemals veröffentlicht oder weitergegeben. Erforderliche Felder sind mit * markiert

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>