2011-07-21 43 views
2

我在Google文檔中有一個包含一個頁面的模板文檔。我想創建一個N頁面的新文檔,每個頁面都與模板文檔中的一個頁面相同。Google應用腳本複製文檔頁面

我該怎麼做?

+0

嗨,你爲什麼要刪除自己的答案嗎?這是正確的方法,只是有點不完整...... ;-) –

+0

如果我沒有記錯,我的解決方案停止工作,因爲谷歌改變了界面。 – oneself

回答

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); 
    } 
    } 
} 
相關問題