Google应用脚本复制文档页面 [英] Google app script copy document page

查看:91
本文介绍了Google应用脚本复制文档页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a template document in Google Docs containing one page. I would like to create a new document with N pages each identical to the one page from the template document.

我该怎么做?

推荐答案

请看中的多页文本 - 单 - 页 - 模板 - 文档 - 文档 - 它来自定义在文档中提供 ...您应该选择一个您需要的并添加相应的例程。

Please have a look at this post from Henrique, it uses the different doc elements following the definitions available in the doc... you should pick the one you need and add the corresponding routine.

以下是它的原理(代码来自原始帖子):

Here is how it goes (code from the original post):

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

这篇关于Google应用脚本复制文档页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆