You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过Google Apps Script关闭Google Doc表格行跨页溢出?代码属性无效

解决Google Apps Script关闭表格行跨页溢出的问题

是的,存在对应的属性和方法来关闭Google Doc表格行的“Allow row to overflow across pages”选项,你的代码无效是因为使用了错误的属性键。

原因说明

你代码中使用的"allowBreakAcrossPages"并非Google Apps Script官方定义的文档属性,正确的属性应该使用DocumentApp.Attribute.BREAK_INSIDE,搭配DocumentApp.BreakInside.AVOID值来实现禁止行跨页的效果。

修正后的代码

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({
      [DocumentApp.Attribute.BREAK_INSIDE]: DocumentApp.BreakInside.AVOID
    });
  }
}

补充说明

  • DocumentApp.Attribute.BREAK_INSIDE用于控制元素内部的分页行为
  • DocumentApp.BreakInside.AVOID表示避免在元素内部分页,对应关闭“Allow row to overflow across pages”选项
  • 如果需要恢复允许跨页,可将值改为DocumentApp.BreakInside.ALLOW

内容的提问来源于stack exchange,提问作者user1765523

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.28 14:17:19