Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Fastest way to fill an InDesign table with data

New Here ,
Aug 26, 2014 Aug 26, 2014

Hello,

I have to fill several InDesign tables with the content of my database.

I have the database in memory and fill the cells in two Loops (For Each row..., For Each col...).

But it is so slow! Is there a faster way?

Here a code snippet of the solution today:

            For Each row In tableRecord
                Dim inDRow = table.Rows.AsEnumerable().ElementAt(intRow)


                For Each content In row
                    Dim cell = inDRow.Cells.AsEnumerable().ElementAt(content.Index)

                    cell.Contents = content.Value


                Next

                intRow+=1

            Next

Thank you for help!

Best regards

Harald

TOPICS
Scripting
1.6K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
Aug 26, 2014 Aug 26, 2014

A faster way would probably be to add your data as regular text,

separated by tabs and paragraph breaks. Then, get a reference to the

first and last character of the text you have added, and run a

myText.convertToTable() on it.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 26, 2014 Aug 26, 2014

Good idea! Thank you. I will try!

I read about XML Import.

Is this also a possible way?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Aug 26, 2014 Aug 26, 2014

Hi,

The question also is:  if you want to create a table from data OR fill existing (formatted) table with data?

table.contents is an array of cell.contents (order by index) - so you can assign an array if it structure match your table size.

I mean, if your array is 24 elements and your table is 4x6 dimension - you can use:

table.contents = array;

Jarek

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 26, 2014 Aug 26, 2014

Hi Jarek,

thank you for this hint!

Yes, I want to fill the data in an existing table.

So your idea works for me.

The array must also include the header rows.

This is really faster, than my solution

Harald

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 26, 2014 Aug 26, 2014

@Harald – I can only speak of my experience with ExtendScript (JavaScript), but with large tables it seems that InDesign is substantially faster converting text to table than assigning contents to a prebuilt table. Of course you'll lose the original formatting of your original one.

I had one case with about 100,000 cells (fortunatelly formatting was no issue in this case) and a lot of text in it.
Read the contents to an array, did some sorting and contents manipulation in the array, wrote out a text file of the contents, removed the original table, placed that text file in the story of the now removed table and converted to table again.

That was tremendously faster than assigning the new contents to the table already built.

Uwe

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 27, 2014 Aug 27, 2014

Hi Uwe,

thank you for sharing your experience.

I have a question. In your example, you have the content already in an array.

Is it really faster to use the ConvertToTable(): write Array in text file, place text file and ConvertToTable?

This should be faster: table.Contents=Array. Or not?

Other Point: In my first solution I use two Loops.

It is faster, when I make the text box height smaller.

Then InDesign is faster, because the cells are not visible.

Best regards

Harald

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 27, 2014 Aug 27, 2014

Hi, Harald!

"This should be faster: table.Contents=Array. Or not?"


Surprisingly is was not. It was slower. A lot slower.

The array was gathered by (here ExtendScript(JavaScript) dummy code) :

myArray = myTable.contents;

Then I did operate on the array. Not on the table object or its cell objects. No direct access to InDesign's DOM objects. Just the built array.

My text file was written by populating it with a string of the array:

myString = myArray.join("separatorString");

separatorString was something that was never used as contents in the table.
Something like "§§§"…

After importing the text file I used the convertToTable() method providing the separatorString as separator for the first and second argument with the number of columns as third argument. The number of columns was known from my original table.

var myNewTable = myText.convertToTable("separatorString", "separatorString", myNumberOfColumns);

Alternatively you could also remove the table after building the array and assign "myString" as contents for the insertionPoint of the removed table in the story. I think I tested that as well, but do not know, if there is a difference in speed opposed to placing a text file with the same contents (I think it was, but not I'm not sure anymore). So I ended up with:

1. Contents of table to Array
2. Array manipulation

3. Array to String

4. Write String as file

5. Remove table

6. Place file at InsertionPoint of (now removed) table

Also to note: This was in InDesign CS5 with a very large table.
Things could have changed in InDesign versions with 64-Bit support.

But I did not test that yet. The customer I wrote this script for is still on CS5.

Uwe

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 27, 2014 Aug 27, 2014
LATEST

Hi Uwe,

it is also a surprise for me, that ConvertToTable() is faster.

Maybe because InDesign can write all data in an unformatted table.

I have in my application (building a catalog page) a formatted table.

So it is better for me to assign the array directly to the table.Contents.

Harald

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines