4 Replies Latest reply on May 9, 2008 4:05 AM by (Dave_Saunders)

    CS3 [JS] Speed Issues with Table Formating

    Level 1
      Hi there

      Please find below an excerpt from my table formatting script. Script as such runs perfectly and does its job well. But it's quite slow thanks to the "formatTable" function (at least that's what Extend Script profiler says).

      What I want it to do is to set the same border for each cell. In its current state it takes it three to five minutes to crunch through 300 rows.
      So I naturally started to wonder whether I'm really doing it the most clever way.

      Thanks for Help

      function formatTable(){
      //~ myTable.cells.everyItem().bottomEdgeStrokeType="Solid";
      //~ myTable.cells.everyItem().topEdgeStrokeType="Solid";
      //~ myTable.cells.everyItem().leftEdgeStrokeType="Solid";
      //~ myTable.cells.everyItem().rightEdgeStrokeType="Solid";
      //~ myTable.cells.everyItem().bottomEdgeStrokeWeight=".25pt";
      //~ myTable.cells.everyItem().topEdgeStrokeWeight=".25pt";
      //~ rightEdgeStrokeWeight=0;
      //~ myTable.cells.everyItem().leftEdgeStrokeWeight=0;

      for (i=myTable.rows.length;i>0;i--){
      focus = myTable.rows[i-1].cells.everyItem();
      with (focus){
      bottomEdgeStrokeType="Solid"; topEdgeStrokeType="Solid"; leftEdgeStrokeType="Solid"; rightEdgeStrokeType="Solid";
      bottomEdgeStrokeWeight=".25pt"; topEdgeStrokeWeight=".25pt"; rightEdgeStrokeWeight=0; leftEdgeStrokeWeight=0;
      }
      $.writeln("Formating Table: " + i + "/" + myTable.rows.length);
      }

      * myTable is a reference to processed table
      ** I've included both (equally slow) approaches, one being commented out
        • 1. Re: CS3 [JS] Speed Issues with Table Formating
          Level 1
          var cp = {
          bottomEdgeStrokeType:"Solid", topEdgeStrokeType:"Solid", leftEdgeStrokeType:"Solid", rightEdgeStrokeType:"Solid",
          bottomEdgeStrokeWeight:".25pt", topEdgeStrokeWeight:".25pt", rightEdgeStrokeWeight:0, leftEdgeStrokeWeight:0
          };

          for (i=myTable.rows.length;i>0;i--){
          myTable.rows[i-1].cells.everyItem().properties = cp;
          }

          jxswm
          • 2. Re: CS3 [JS] Speed Issues with Table Formating
            Level 1
            Thanks jxswm

            I used your approach and shaved off 80% of the time that the script runs
            • 3. Re: CS3 [JS] Speed Issues with Table Formating
              Level 1
              what if you use .itemByRange ??

              myTable.cells.itemByRange(myTable.cells.item[0],myTable.cells.item[-1]).item[1].propertie s = cp;

              or something like this ;) I'm not JS man

              of course if you need to style all cells in whole table ...

              or just define TableStyle ...

              robin

              --
              www.adobescripts.com
              • 4. Re: CS3 [JS] Speed Issues with Table Formating
                Level 1
                When working with table cells, everyItem() and itemByRange(0,-1) produce different results.

                myTable.cells.everyItem()

                gives you (in effect) a reference to every cell individually.

                myTable.cells.itemByRange(0,-1)

                gives you (in effect) a reference to all the cells of the table as a range.

                The difference is important when working with cell stroke properties. For example, individual cells don't have innerColumnStrokes nor innerRowStrokes. Conversely, referring to the edgeStrokes will affect every cell when using everyItem(), but only the outside (i.e., edge) cells when using itemByRange.

                I think this might be the only place in the object model where these two calls produce different results. I'd be happy to hear if anyone knows of any other instances.

                Dave