2016-10-23 6 views
0

誰でもこのコードが「無効な色ですか?」というエラーを返す理由を教えてもらえますか?無効なBACKGROUND_COLORですか?

これは、BACKGROUND_COLOR属性を参照しているようです。しかし、私は理由を理解できません。

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

INVALID COLORが返されません。あなたのコードをテストし、背景色に関するエラーはありません。 http://imgur.com/LxBMvIZ 新しいスクリプトプロジェクトにカラーコードをコピーして、それが実際にエラーの原因であるかどうかを確認してください。 – noogui

+0

16進数の代わりに文字列を使用してください。 (参考:https://developers.google.com/apps-script/reference/document/attribute) –

答えて

0

あなたはヘックスコード・フォーマットを使用することができますが、引用符の内側にそれを置くことを忘れないでください:

// 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); 

そして、ここであなたが試すことができますHex Codesのリストです。

関連する問題