【发布时间】:2026-02-02 09:55:01
【问题描述】:
我尝试在 Google doc 文件的现有表格中添加新行,但表格属性未应用于新行。我能够通过样式保存 2 个单元格。这是 Apps 脚本函数
function addRow(fileId)
{
var body = DocumentApp.openById(fileId).getBody(),
searchElement = body.findElement(DocumentApp.ElementType.TABLE),
element = searchElement.getElement(),
table = element.asTable();
var cell1Style = table.getRow(0).getCell(0).getAttributes();
var cell2Style = table.getRow(0).getCell(1).getAttributes();
cell1Style[DocumentApp.Attribute.BACKGROUND_COLOR] = '#ffffff';
cell2Style[DocumentApp.Attribute.BACKGROUND_COLOR] = '#ffffff';
var rowStyle = {};
rowStyle[DocumentApp.Attribute.BORDER_COLOR] = '#000000';
var tr = table.appendTableRow();
tr.setAttributes(rowStyle);
tr.appendTableCell('My Text:').setAttributes(cell1Style);
tr.appendTableCell('My value').setAttributes(cell2Style);
}
正如您所见,即使我设置了边框颜色属性,新行也出现在表格之外。请帮忙
【问题讨论】:
标签: google-apps-script google-docs google-docs-api