如何通过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
相关产品推荐
相关产品推荐

