我想做的是:
我能够一个接一个地插入两个表,但是在插入表2之前无法中断到新页面。
docId = "YOUR_DOC_ID";
var doc = DocumentApp.openById(docId);
var body = doc.getBody();
var table1 = body.insertTable(2, data[0]);
formatTable(table1);
// insert page break here
var table2 = body.insertTable(3, data[1]);
formatTable(table2);
doc.saveAndClose();
insertPageBreak()是我正在努力解决的问题。
到目前为止我一直尝试的:
appendPageBreak
上找到body
。所以我尝试了body.appendPageBreak()
。这将在“非常”端插入一个新页面。但是我需要在表1之后。getCursor()
命令,我得到NULL。同样,theElement.insertPageBreak(0)
对我也失败了,因为element没有显示任何insertPageBreak()
方法。任何帮助将不胜感激。
答案 0 :(得分:1)
尽管我不确定您的实际文档,但是如果使用了新文档,该修改如何?修改后的脚本的流程如下。
在此脚本中,将表1,分页符和表2放入新文档中。
docId = "###";
var body = DocumentApp.openById(docId).getBody();
var table1 = body.insertTable(1, [["table1"]]);
body.insertPageBreak(2);
var table2 = body.insertTable(3, [["table2"]]);
在此脚本中,通过提供插入索引,将表1,分页符和表2从插入索引中放到文档中。
var insertIndex = 1; // Please set this
docId = "###";
var body = DocumentApp.openById(docId).getBody();
var table1 = body.insertTable(insertIndex, [["table1"]]);
var pageBreak = body.insertPageBreak(body.getChildIndex(table1) + 1);
var table2 = body.insertTable(body.getChildIndex(pageBreak.getParent()) + 1, [["table2"]]);
_insertPageBreak()
。如果我误解了您的问题,而这不是您想要的结果,我深表歉意。