1 Reply Latest reply on Feb 7, 2011 4:07 PM by Marc Autret

    Scripting Tables : Best Practices

    Loic.Aigon Adobe Community Professional

      Hi all,


      I don't pretend to be exhaustive here but as I did notice a few things while scripting tables, I wanted to share them here and maybe let you fill the blanks.


      So if you are scripting tables, here is(are) some recommended practices based on experience :


      Check if a row (or cell) is empty :

      Avoid : row.contents or cells.contents to check content. It was a major crash issue in my script

      Prefer : row.findGrep() after setting findGrepPreferences.findWhat="." and check found.length==0;


      Fill content :

      Avoid : looping adding rows with a loop after table creation

      Prefer : create an array with all the datas and pass it as the table contents

                  or create a bunch of bodyRows and target specific cells for filling datas.


      Be careful, if you choose for the table.contents = []; //Array of strings for every cell, YOU HAVE to declare any array elements;

      table.contents=["a",,"c"]; will fail ! It's important to set a string even if it's empty !!!

      table.contents=["a","","c"]; //thus presuming the table is made of one row/3cols or 1col/3row.



      Feel free to amend.



        • 1. Re: Scripting Tables : Best Practices
          Marc Autret Level 5

          Hi Loïc,


          About your first point, I do not recommend using the findGrep() artillery to check whether a Row or a Cell is empty. This sounds quite expensive to me!


          • In most case myRow.contents returns an Array of Strings, or simply a String if myRow has a single Cell. Depending on that context you might have to check myRow.contents.join('') rather than myRow.contents.


          However I admit that working on myRow.contents (or myCell.contents) is usually not a good approach in most scripting situations, because these properties only return the visible contents and ignore the case where the targetted Cell(s) overflows. This may be the source of many bugs —while indeed the findGrep() method looks into the hidden contents et return the desired result.


          • But the Characters collection of a Cell also can see the hidden contents, so I think that a better (faster?) checkEmpty routine should be based on:








          Thus you don't need to invoke findGrep() or findText().


          Hope that helps ;-)