2017-09-15 4 views
0

Cette fonctionAppend note au corps (avec formatage)

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

toutes les notes à l'intérieur ajoute le document du corps, mais la mise en forme du se perd .... comment puis-je faire de sorte qu'il sera formaté ainsi (mot par mot, j'en ai besoin pour préserver les mots italiques et gras)?

Répondre

0

Les notes de bas de page sont des objets dans Google, vous devez donc accéder à chaque objet et extraire le texte de la chaîne. Vous devez utiliser .getFootnoteContents() conjointement avec la méthode .copy() pour copier les propriétés du Footnote.

More on the copy method

Changer votre code:

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

Merci beaucoup, cela a fonctionné comme prévu :) – lucanapo