Google apps script 背景颜色无效?

Google apps script 背景颜色无效?,google-apps-script,google-docs,Google Apps Script,Google Docs,有人能告诉我为什么这段代码返回一个错误,上面写着“无效颜色”吗 它似乎是指背景颜色属性。但我不明白为什么 function myFunction() { var bibiDoc = {}; bibiDoc[DocumentApp.Attribute.BACKGROUND_COLOR] = 0x000000; bibiDoc[DocumentApp.Attribute.FONT_FAMILY] = 'Courier New'; bibiDoc[DocumentApp.Attribu

有人能告诉我为什么这段代码返回一个错误,上面写着“无效颜色”吗

它似乎是指背景颜色属性。但我不明白为什么

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

您可以使用十六进制代码格式,但不要忘记将其放在引号内:

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

这里有一个列表,您可以尝试。

它不会返回无效颜色。我测试了你的代码,没有关于背景颜色的错误。尝试将颜色代码复制到新的脚本项目中,看看这是否真的是错误的原因。尝试使用字符串of而不是十六进制数。(参考资料:)