Google 文档 setHeadingAttributes() 无法正常工作

Google docs setHeadingAttributes() not working properly

我正在尝试使用 setHeadingAttributes() 函数更改 Google 文档上的标题。

  function setHeadings() {
  var doc = DocumentApp.getActiveDocument();
  var body = doc.getBody();

  var myNormal_Style = {};
  myNormal_Style[DocumentApp.Attribute.FONT_FAMILY] = 'PT Serif';
  myNormal_Style[DocumentApp.Attribute.FONT_SIZE] = 12;
  body.setHeadingAttributes(DocumentApp.ParagraphHeading.NORMAL, myNormal_Style);

  var myTitle_Style = {};
  myTitle_Style[DocumentApp.Attribute.FONT_FAMILY] = 'Montserrat';
  myTitle_Style[DocumentApp.Attribute.FONT_SIZE] = 14;
  myTitle_Style[DocumentApp.Attribute.BOLD] = false;
  body.setHeadingAttributes(DocumentApp.ParagraphHeading.TITLE, myTitle_Style);

  var myHeading1_Style = {};
  myHeading1_Style[DocumentApp.Attribute.FONT_FAMILY] = 'Courier New';
  myHeading1_Style[DocumentApp.Attribute.FONT_SIZE] = 14;
  myHeading1_Style[DocumentApp.Attribute.BOLD] = true;
  body.setHeadingAttributes(DocumentApp.ParagraphHeading.HEADING1, myHeading1_Style);



  Logger.log(body.getHeadingAttributes(DocumentApp.ParagraphHeading.TITLE));
  Logger.log(body.getHeadingAttributes(DocumentApp.ParagraphHeading.HEADING1));
  Logger.log(body.getHeadingAttributes(DocumentApp.ParagraphHeading.NORMAL));
}

问题是只有设置 NORMAL 航向才能正常工作。事实上,NORMAL 标题似乎完全覆盖了 TITLE 和 HEADING1,因此它们现在都是 PT Serif 字体。 (将其更改为另一种字体而不是 PT Serif 会相应地更改所有内容)。

检查日志显示一切似乎都很好,但包含此脚本的实际文档显示情况并非如此。我已经尝试注释掉设置 NORMAL 的部分,它表明设置 TITLE 或 HEADING1 实际上除了在日志中什么都不做。我制作了新文档,甚至使用了其他 Google 个帐户,但他们似乎都有这个问题。

从给定的示例中复制和粘贴 , which supposedly works, only confirms my problem, which seems to be the same as in this question without an adequate answer。我似乎无法在我的代码中找到问题。非常感谢您的帮助。

这是一个已在 Public Issue Tracker 上提交的错误:

https://issuetracker.google.com/36763968

您可以开始提高知名度。

与此同时,您可以使用一种变通方法手动遍历所有段落并将不同的属性应用于不同的标题,例如完成 here.