2016-10-23 1 views
0

Quelqu'un peut-il me dire pourquoi ce code renvoie une erreur qui dit «couleur invalide?Invalide BACKGROUND_COLOR?

Il semble s'agir de l'attribut BACKGROUND_COLOR. Mais je ne peux pas comprendre pourquoi.

function myFunction() { 
    var bibiDoc = {}; 
    bibiDoc[DocumentApp.Attribute.BACKGROUND_COLOR] = 0x000000; 
    bibiDoc[DocumentApp.Attribute.FONT_FAMILY] = 'Courier New'; 
    bibiDoc[DocumentApp.Attribute.FOREGROUND_COLOR] = 0x00FF00; 
    bibiDoc[DocumentApp.Attribute.FONT_SIZE] = 12; 


    var doc = DocumentApp.getActiveDocument(); 
    var body = doc.getBody(); 
    var par = body.appendParagraph("test"); 

    par.setAttributes(bibiDoc); 
} 
+0

Il ne retourne pas INVALID COLOR. J'ai testé votre code et aucune erreur concernant BACKGROUND COLOR. Essayez de copier les codes de couleur dans un nouveau projet de script pour voir si c'est vraiment la cause des erreurs. – noogui

+0

Essayez d'utiliser une chaîne de caractères au lieu d'un nombre hexadécimal. (référence: https://developers.google.com/apps-script/reference/document/attribute) –

Répondre

0

Vous pouvez utiliser le format de code Hex, mais ne pas oublier de le mettre entre guillemets:

// Define a style with yellow background. 
var highlightStyle = {}; 
highlightStyle[DocumentApp.Attribute.BACKGROUND_COLOR] = '#FFFF00'; 
highlightStyle[DocumentApp.Attribute.BOLD] = true; 

// Insert "Hello", highlighted. 
DocumentApp.getActiveDocument().editAsText() 
    .insertText(0, 'Hello\n') 
    .setAttributes(0, 4, highlightStyle); 

Et voici une liste des Hex Codes vous pouvez essayer.