是否有 Google Apps 脚本属性或方法来关闭现有 Google 文档中表格的“允许行跨页溢出”行选项?
我有下面的缩写代码可以正确检索表格,但属性值无效。
var body = DocumentApp.getActiveDocument().getBody();
var tables = body.getTables();
for (var i = 0; i < tables.length; i++) {
var table = tables[i];
var rows = table.getNumRows();
for (var j = 0; j < rows; j++) {
var row = table.getRow(j);
row.setAttributes({ "allowBreakAcrossPages": false });
}
}
我相信你的目标如下。
不幸的是,目前阶段似乎没有办法用谷歌文档服务(DocumentApp)取消选中它。但是,幸运的是,当使用 Google Docs API 时,这是可以实现的。在这个答案中,我想建议使用 Google Docs API。示例脚本如下
在使用此脚本之前,请在高级 Google 服务中启用 Google Docs API。
还有,请设置你要使用的表索引。在此示例中,文档中的第一个表与
const table = body.getTables()[0];
一起使用。
function myFunction() {
const doc = DocumentApp.getActiveDocument();
const documentId = doc.getId();
const body = doc.getBody();
const table = body.getTables()[0]; // Please set the index of the table.
const index = Docs.Documents.get(documentId).body.content[body.getChildIndex(table) + 1].startIndex;
const requests = [{
updateTableRowStyle: {
tableRowStyle: { preventOverflow: true },
tableStartLocation: { index },
fields: "preventOverflow",
}
}];
Docs.Documents.batchUpdate({ requests }, documentId);
}
preventOverflow: true
修改为preventOverflow: false
。