2017-09-15 1 views
0

Diese FunktionAnfügen Notizen zu Körper (mit Formatierung)

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

alle Noten im Inneren des Körpers Dokument anhängt, aber die Formatierung der verloren geht .... wie kann ich es tun, es so gut formatiert wird (Wort für Wort, ich brauche es, um kursiv und fett zu bleiben)?

Antwort

0

Fußnoten sind Objekte in Google. Sie müssen also auf jedes Objekt zugreifen und den Text der Zeichenfolge extrahieren. Sie müssen .getFootnoteContents() in Verbindung mit der .copy() Methode verwenden, um die Eigenschaften des Footnote zu kopieren.

More on the copy method

Code ändern zu:

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

vielen Dank, es hat funktioniert wie beabsichtigt :) – lucanapo