Saturday, July 29, 2006

 

Cracked it, But...

First, I walked into another trap. Here is my first attempt to address the issue. I decided to make my two variables theCols and theRows record objects that contain two properties named start and end into which I put the relevant row and column indexes, like this:
if ((app.documents.length == 0) || (app.selection.length == 0)) { exit() }

aDoc = app.activeDocument;
aSel = app.selection[0];

try {
theCols = {start: aSel.cells[0].name.split(":")[0],end: aSel.cells[-1].name.split(":")[0]};
theRows = {start: aSel.cells[0].name.split(":")[1],end: aSel.cells[-1].name.split(":")[1]};
theTable = aSel.parent;
} catch (e) {
alert("Selection needs to be in a table, and rectangular"), exit();
}

alert(theTable.columns[theCols.start].cells[theRows.start].contents);
And blow me but I still got the wrong value. This time, I got the cell below the one I was expecting to get. Why? because of a merged row in the top row of the table. That means that the column I'm looking at doesn't have a cell in that row, so using the cell row number as an index to the column's cells misses by one (in this case).

The correct way to address the cell I need is:
alert(theTable.cells.item([theCols.start] + ":" + [theRows.start]).contents);
which looks pretty ugly, but it has the benefit of working!

Comments: Post a Comment

<< Home

This page is powered by Blogger. Isn't yours?