将注释附加到正文(带格式)

Append notes to body (with formatting)

这个函数

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

将所有注释附加到正文文档中,但格式丢失了....我该怎么做才能使其也格式化(逐字逐句,我需要它来保留斜体和粗体字) ?

脚注是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);
}