繁体   English   中英

谷歌应用脚本复制文档页面

[英]Google app script copy document page

我在 Google Docs 中有一个包含一页的模板文档。 我想创建一个包含 N 页的新文档,每页与模板文档中的一页相同。

我怎样才能做到这一点?

请看一下 Henrique 的这篇文章,它使用了文档中可用定义之后的不同文档元素……你应该选择你需要的并添加相应的例程。

这是它的运行方式(来自原始帖子的代码):

function mergeDocs() {
  var docIDs = ['list-of','documents','ids','you should have somehow'];
  var baseDoc = DocumentApp.openById(docIDs[0]);
  var body = baseDoc.getActiveSection();

  for( var i = 1; i < docIDs.length; ++i ) {
    var otherBody = DocumentApp.openById(docIDs[i]).getActiveSection();
    var totalElements = otherBody.getNumChildren();
    for( var j = 0; j < totalElements; ++j ) {
      var element = otherBody.getChild(j).copy();
      var type = element.getType();
      if( type == DocumentApp.ElementType.PARAGRAPH )
        body.appendParagraph(element);
      else if( type == DocumentApp.ElementType.TABLE )
        body.appendTable(element);
      else if( type == DocumentApp.ElementType.LIST_ITEM )
        body.appendListItem(element);
      else
        throw new Error("According to the doc this type couldn't appear in the body: "+type);
    }
  }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM