【发布时间】:2021-12-15 00:58:27
【问题描述】:
我正在尝试修改具有多行但每行具有不同列数的 google 文档表。
如何使用 table.getCell(row,col) 或 row.getCell(col) 来获取 a,b,c,d,e,f,g 等的内容。
解决每个单元格和修改内容的正确方法是什么。我正在处理的表具有已定义的结构。
tables.forEach(function(table) {
var numberOfRows = table.getNumRows();
console.log("New Table with Rows: " + numberOfRows);
for (var rowIndex = 0; rowIndex < numberOfRows; rowIndex++) {
var row = table.getRow(rowIndex);
// this is a table of interest and we know the exact structure
if(rowIndex == 0 && row.getCell(0).getText().toString().trim().includes("2 cols")){
row.getCell(0).editAsText().setText("11");
row.getCell(1).editAsText().setText("12");
}else if(rowIndex == 1 && row.getCell(0).getText().toString().trim().includes("3 cols")){
row.getCell(1).editAsText().setText("21");
row.getCell(2).editAsText().setText("22");
}else if(rowIndex == 2 && row.getCell(0).getText().toString().trim().includes("5 cols")){
row.getCell(1).editAsText().setText("31");
row.getCell(2).editAsText().setText("32"); // NOTE1: THIS IS THE ISSUE
row.getCell(3).editAsText().setText("33"); // NOTE3: THIS IS THE ISSUE
}
}
})
为什么 NOTE1 和 NOTE2 没有修改单元格 e 和单元格 f?
【问题讨论】:
标签: google-apps-script google-docs