I'm trying to automatically format a table in a Google Doc cell by cell. Once I have a table stored in the variable table
, I try to use getCell
to reference the cell in the top left of this table, but it doesn't return the cell I'm after.
I noticed that in the Google Scripts reference, they note that to point to a cell, the correct usage is getCell(rowIndex, cellIndex)
. What does cellIndex
refer to in this case, and does it relate to some sort of columnIndex
?
Any pointers on this would be appreciated.
Editing a table in a Google Doc
Here's an example that edits all of the cell contents of a table selected by placing the cursor inside one of it's cells.
rowIndex goes from 0 to
table.getNumRows()-1;
cellIndex goes from 0 to
table.getRow(i).getNumCells()-1
Yes, the cellIndex refers to columnIndex. Consider the below example
Here, the value in Logger will retrieve the cell value in first row and first column of the table. the index for row and column starts from 0.
Hope this helps!.