2017-09-15 28 views
0

此功能追加說明,以體(具有格式化)

function appendiNote() { //appende tutte le note ma senza formattazione.. 
    var note = DocumentApp.getActiveDocument().getFootnotes(); 

    for (var i = 0; i < note.length; i++){ 
    var par = note[i].getFootnoteContents(); 
    DocumentApp.getActiveDocument().getBody().appendParagraph((i+1)+par.getText());  
    } 

追加體文檔中的所有注意,但對格式丟失....我該怎麼做,所以它被格式化爲好(一個字一個字,我需要它來保存斜體和大膽的話)?

回答

0

腳註是Google中的對象,所以您需要訪問每個對象並提取字符串文本。您需要結合使用.getFootnoteContents().copy()方法來複制Footnote的屬性。

More on the copy method

更改您的代碼:

function appendiNote() { 
    // Gets all footnotes in the document as an iterable array 
    var notes = DocumentApp.getActiveDocument().getFootnotes(); 

    // iterate through the notes array 
    for (var i = 0; i < notes.length; i++) { 
    // for each item, get the contents of the object 
    var note = notes[i].getFootnoteContents(); 

    // create a deep copy of the object, which includes styles. 
    var par = note.getChild(0).copy(); 

    // Append the footnote, including styles, as a paragraph in the body of the doc. 
    DocumentApp.getActiveDocument().getBody().appendParagraph(par); 
} 
+0

太感謝你了,它的工作如預期:) – lucanapo