使用脚本将 table 放在 Google Docs 文档的顶部

Put a table at the top of a Google Docs document with a script

我一定是遗漏了一些明显的东西 - 但是如何使用 Google Apps 脚本将 table 添加到文档的顶部。我知道这个:

var doc = DocumentApp.getActiveDocument();
var top = doc.getBody().getChild(0);
top.asParagraph().insertText(0, data);

将我的变量(在本例中为 'data')放在文档的顶部 - 但我似乎无法在此位置使用 append.table 做任何事情?

要插入 table,请使用 Body 对象的 insertTable 方法。

function insertTable() {  
  var doc = DocumentApp.getActiveDocument();
  doc.getBody().insertTable(0, [['This', 'is'], ['my', 'table']]);
}

第一个参数是 table 的索引:0 = 文档的开头。