2017-09-15 84 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