从Google文档中删除表格

时间:2017-01-11 09:46:44

标签: google-apps-script

我是GAS的新手,我试图弄清楚如何列出DOC中的元素,以便删除表格。我似乎无法找到对此的参考,以及操纵" children"的语法。还是超出了我。

有人可以帮忙吗?

1 个答案:

答案 0 :(得分:0)

您可以使用Table Class .removeFromParent()https://developers.google.com/apps-script/reference/document/table#removeFromParent()

function myFunction() {
 var body = DocumentApp.getActiveDocument().getBody();
 var tables = body.getTables(); //THIS WILL GET ALL TABLES IN DOC
 tables[0].removeFromParent(); //THIS WILL REMOVE FIRST TABLE
}

如果你有表(var表),​​你可以循环遍历它们,如果你想删除多个表。