Skip to main content
Known Participant
May 8, 2008
Question

CS3 [JS] Speed Issues with Table Formating

  • May 8, 2008
  • 4 replies
  • 594 views
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
This topic has been closed for replies.

4 replies

Inspiring
May 9, 2008
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
Known Participant
May 9, 2008
what if you use .itemByRange ??

myTable.cells.itemByRange(myTable.cells.item[0],myTable.cells.item[-1]).item[1].properties = 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
Known Participant
May 9, 2008
Thanks jxswm

I used your approach and shaved off 80% of the time that the script runs
Known Participant
May 8, 2008
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