2015-04-16 124 views
0

我正在研究Google腳本,以便從文檔中的腳註中創建尾註。除了在腳註被移除之後替換上標,所有東西都在起作用。具體來說,我不能得到一個for循環開始計數在1而不是零。無法獲得循環打印正確

腳本的位是:

function replaceNotes() { 
    var par = body.getParagraphs(); 
    var notes = DocumentApp.getActiveDocument().getFootnotes(); 

    for(var i in notes){ 
    notes[i].getParent().editAsText().appendText(i); 
    return; 
    } 
} 

這工作,但它從0開始,預計打印。因此,我將循環設置爲for(var i = 1; i < notes; i++)...,並且在運行時不再顯示值。看看這些文檔,我沒有看到腳本無法正常工作的原因。我錯過了明顯的東西嗎?

+0

回答

0

你需要得到音符的長度notes.length

function replaceNotes() { 
     var par = body.getParagraphs(); 
     var notes = DocumentApp.getActiveDocument().getFootnotes(); 

     for(var i = i; i < notes.length; i++){ 
     notes[i].getParent().editAsText().appendText(i); 
     return; 
     } 
    }