【问题标题】:Google app script copy document page谷歌应用脚​​本复制文档页面
【发布时间】:2011-07-21 22:55:59
【问题描述】:

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

我该怎么做?

【问题讨论】:

  • 嗨,你为什么删除自己的答案?这是正确的方法,只是有点不完整...... ;-)
  • 如果我没记错的话,我的解决方案停止工作是因为谷歌改变了界面。

标签: google-apps-script google-docs


【解决方案1】:

请看一下 Henrique 的 this post,它使用了 available in the doc 定义之后的不同文档元素...你应该选择你需要的并添加相应的例程。

这是怎么回事(来自原始帖子的代码):

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);
    }
  }
}

【讨论】:

    猜你喜欢
    • 2015-04-15
    • 2013-11-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多