开发者

Google app script copy document page

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.

How can I do this?


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜