引用Google文档中表格中的单元格 [英] Referencing cells in tables on a Google Doc
问题描述
我正在尝试按单元格自动设置Google Doc单元格中的表格格式.一旦将表存储在变量table
中,我尝试使用getCell
引用此表左上角的单元格,但它不会返回我要的单元格.
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.
我注意到在Google脚本参考中,他们注意到指向单元格的正确用法是getCell(rowIndex, cellIndex)
.在这种情况下,cellIndex
指的是什么,它与某种columnIndex
有关吗?
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
?
对此有任何建议.
推荐答案
在Google文档中编辑表格
下面是一个示例,该示例通过将光标放在其中一个单元格内来编辑表的所有单元格内容.
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从0变为table.getNumRows()-1;
rowIndex goes from 0 to table.getNumRows()-1;
cellIndex从0变为table.getRow(i).getNumCells()-1
cellIndex goes from 0 to table.getRow(i).getNumCells()-1
function editTableAtCursor(){
var doc=DocumentApp.getActiveDocument();
var el=doc.getCursor().getElement().getParent().getParent().getParent();
var table=el.asTable();
var rows=table.getNumRows();
for(var i=0;i<table.getNumRows();i++) {
for(var j=0;j<table.getRow(i).getNumCells();j++) {
table.getCell(i,j).editAsText().setText(Utilities.formatString('Row: %s Cell: %s',i,j));
}
}
}
- 表类
- 将表替换为数组的示例
- Table Class
- Example that replaces table with an Array
这篇关于引用Google文档中表格中的单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!