Thanks for coming to InDesignSecrets.com, the world's #1 resource for all things InDesign!

Using Data Merge to Create a Table for a Directory

For years we’ve been saying: Data Merge is terrible for creating directories. The reason is that InDesign’s Data Merge feature takes a “prototype” example and repeats it (either once per page, or in a grid on your pages) — that is, it duplicates the text and graphic frames themselves over and over. That makes it great for things like a yearbook or contact sheet, or business cards or anything that requires variable data within a particular layout.

But it’s terrible for directories where you just need a one long list or table of information. Until now.

Loic Aigon wrote this wonderful little free script called CSVtoTables that lets you use Data Merge with a table! Normally, Data Merge would simply duplicate the whole text frame that contains the table, which is useless. This script lets you duplicate the rows themselves, all in the same table. Here’s how it works.

Here’s the data we’re working with, in Excel:

table merge from excel

Now I save this as a CSV (comma-delimited) or TXT (tab-delimited) data file, switch to InDesign and choose Select Data Source from the Data Merge panel menu. This loads my table into the Data Merge panel. (Notice that it uses the column header row in the spreadsheet above as the name of the data tags.)

creating the prototype

I create a table in an InDesign text frame, then place the Type tool into the frame and click on each Data Merge tag I want to include. (You don’t have to include all of them.) In the example above, I’m using a two-column table with a header row. I’ve also created and applied paragraph styles to the tags inside the table. I strongly recommend you save your document/template now, so that you can revert to it later if you need to.

Now comes the magic. Select the row you want to repeat (in this case, the second row, with the data merge tags in it). You have to have the whole row selected of you’ll get a javascript error! Now run the script from the Script panel by double-clicking on it.

The result:

final result

Note that many of the “Street 2” cells were empty in the original data? that’s okay, the script strips those lines out so that they don’t appear in the final table. Yay! Because I had set the original row’s height to “At Least 3 mm” each row is only as tall as it needs to be. (Of course, if you prefer each row be exactly the same height, you can do that, too.)

By the way, the script changes the table in your current document. (That’s different than the way Data Merge normally works, which is to create a duplicate of your document.) So when you’re done, choose File > Save As, so that you don’t overwrite your original template/prototype table accidentally (you might need it again later!).

Of course, there are many other commercial plug-ins (such as Em Software’s InData) that let you create far more complex and fancy directories based on spreadsheet or database data. But for a simple directory, where you just need a long multi-page table, this free script is awesome.

You can download the script here; if you need help installing the script, read this.

David Blatner

David Blatner

David Blatner is the co-founder of the Creative Publishing Network, InDesign Magazine, and the author or co-author of 15 books, including Real World InDesign. His InDesign videos at Lynda.com are among the most watched InDesign training in the world. You can find more about David at 63p.com.
David Blatner

Latest posts by David Blatner (see all)

  • - November 30, -0001
Tags
Related Articles
Comments

40 Comments on “Using Data Merge to Create a Table for a Directory

  1. This is a great find, but for me it begs the question “could it work WITHOUT the table cells?” Data Merge has had the problem that it could never emulate Word’s “Next Record” field to put the next record in the same text box, but Loic’s script has, in a way, found this via table rows… but what if the data was just repeating in the same text box without being in a table?

  2. Perhaps I am a bit thick here, but please explain to me how this is different than using indesigns “Convert Text to Table”?

  3. @Stephan: DataMerge lets you import selected data from a spreadsheet or database and format it upon import (including images). Convert Text to Table requires that everything already be formatted.

  4. I cannot access the scriptopedia.org site.
    When I go to InDate/Xdata (by Em Software) it costs $400 to allow more than 50 records of data. Regardless of cost I am still not able to use this product. The Script itself is not showing up in my scripts after I install it. Is there something I am missing? Are the 2 scripts not the same?

  5. Hm, I’m having some difficulties with this script.
    I’ve setup 1 column with 1 row. In that one cell I’ve
    added multiple tags, with each it’s own paragraph style.
    So far, so good. But when I run the script all the generated
    input has been set to, say, “paragraph style 1+” Even though
    it should be, for example, “paragraph style 2”.

    And I just found that same goes for when you select preview, scroll
    trough preview and un-check preview.

    one style per cell works like a charm though…

  6. I have 2 sets of images and multiple text frames that I want to repeat on the same page. Everything is styled but not in a table. Would the script CSVtoTables allow the second set of data to pull in the second line of content from my excell spread sheet? Right now what is happening is Indesign is repeating the data and pulling in the next line of data and pictures on the next page. Any ideas?

  7. Most excellent! I’ve been trying to overcome the DataMerge duplication pain and this is the ticket!

    I’m using Tick for time tracking and it exports a simple CSV and I was doubting that I’d have to import every DataMerge tag into every cell. Halleluja!

    • Ahhh, poop. Too excited. I followed the instructions and it tells me “done” after flashing two new documents and promptly closing them. The DataMerge tags are in the table, I selected the row, and then it does nothing but flash those documents open/closes them and deletes the merge tags. This is in CS6.

  8. Is there a way I can alter this for text boxes & actions in the case of say a certificate. say I have for example an indesign doc that is a certificate going out to many people and I have an excel column listing those people… either one column full name or 2 columns first and last.

    Is there a way I could re-purpose this to add names to the text field, going down the column in order and saving the file as a pdf with actions every time a name is changed.

    So the script would run; change the name. this could then trigger the action, the action would save the files a pdf and that would trigger the script to add the next name.

    Kind of complex; my knowledge of scripts is currently limited but it would be cool and useful for lots of things.

  9. Your data merge tuts have helped me so much!
    Do you know of any way to make it work with arabic text as well though?

  10. Ok thanks I haven’t ever used the Data Merge feature. I will have to look into that, I just assumed it would involve a script but I am not an advanced indes user… more intermediate ha I’ll take a look at that thanks!

  11. This is a great script, but I’m wondering if there’s a way to attach a link to an actual cell, but the cells can disappear if the CSV has no info in the cell upon import (allowing for rows to be omitted as necessary)?

  12. I’m having issues using this script in InDesign CS6. Whenever I run the script, another window in InDesign opens with a tiny text box in the corner. When you expand the box and the table inside, it just has the merge fields in there.

    Has anyone else encountered this problem and found a solution? Thanks.

  13. Is it possible to add additional rows of information?
    (“Select the row you want to repeat (in this case, the second row, with the data merge tags in it). You have to have the whole row selected of you’ll get a javascript error! Now run the script from the Script panel by double-clicking on it.”)

    I’m wanting to do 6 rows of information (an entire name and address block) and when I select them I only get the first row of information.

  14. Hi,

    Ive got a crazy data merge that i’m not sure is possible.. heres my simplified data

    image, style name, size, price

    first problem I want to have 1 image for 5 records that all have the same image. no idea how to do this?

    2nd problem Id then like to turn it into an order form (interactive pdf) so has a quantity for each row.

    please help!

  15. HI can anyone help me? I have a catalogue already done but for design reason I have to convert all the text frames into table as they are…. in the document I have 100s and 1000s of text boxes and to convert each text box into table one by one will take me for ever, do you have any script where I can select all the text boxes and convert into table?

    thanks

      • Hi and thanks for the reply. I have found something on google and that is exactly what I need but the problem is it is converting table into 4 rows and not one…

        I need one row, one column and no border.. infect if I can apply table Style like top-Line would be great.. I am a graphic designer and not a computer expert so dont understand the languages… If you can have a look at the codes below and correct it for me?

        var myText = app.activeDocument.selection[0].texts[0];
        var myTable = myText.convertToTable();

        really appreciate and many thanks. (also this only does the one table and not all selected.. it would be nice if I select all and convert all but if not one would be fine.. it saves me doing manual all, with this script I just have to click, much faster than going into each table, select and convert)

  16. Hi,

    I’ve used this script before multiple times but I am trying to use it again on a new project and I can’t for the life of me get it to display my images.

    I have 12 columns in landscape and have them all tagged correctly. I have the image frame in the 12th column tagged correctly as well. The filepaths in the .csv are correct. When I run the script it fills out all the columns and rows with the data except the images. The tagged image frame just remains in the first row. If I goto preview in the data merge window before running the script it will load the first image of the first data entry.

  17. I would like to create a directory listing with just text flowing in from different columns from excel.

    EG- create this repeated with two hard returns within text column and next set of information applied with paragraph styles applied when imported:
    First Last name
    Address
    City, State 00000
    (000) 000-0000

    From this excel columned document:

    First Last name (Column 1) Address (Column 2) City (Column 3) State (Column 4) Zip (Column 5) Phone (Column 6)

    I would like to be able to change the excel document and able to update within InDesign. Also be able to apply tabs to different pages.

    Thanks!

  18. I must be missing something simple. How would I update the data in the table from the csv when changes are made without deleting the data in ID and re-running the script? Is this not possible with this script?

    • Todd: No, data merge (and this script) does not update data. It just has a very simple brain. You have to rerun it if the data changes. (There are commercial plug-ins that are smart like that.)

      • Hello, could you please tell me which commercial plug-ins could do the job ?
        (I just update my indesign, and then the csvtotable script doesn’t work anymore).

        Thank you.

  19. I’m trying to automate the pagination of only two sizes of page ads: Full page and half page (from saved PDFs.)
    My problem is that in no way can I seem to automate the two half pages coming together as one when necessary, while continuing to add the full pages. I’ve tried Data Merge Multiple Records, Tables, Loic’s scripts (Anchored Data merge & CSV to Tables). Help please!

  20. I have everything set up with paragraph styles and linked in the data merge window but I am unable to preview the merge or run the script.

    Amy ideas on how to fix this?

    • I fixed the preview issue but I am still unable to run the script. When I double click or right click and hit run script nothing happens. I know it can take a few minutes but still nothing happens…

      • I found the issue. When I installed the script to the Application folder not user, the script worked perfectly.

Leave a Reply

Your email address will not be published. Required fields are marked *