Google app script copy document page

余生颓废 提交于 2019-12-11 03:38:42

问题


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?


回答1:


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


来源:https://stackoverflow.com/questions/6783819/google-app-script-copy-document-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!