简体   繁体   English

如何在 Apps 脚本中设置字体粗细 - Google Docs

[英]How to Set the Font Weight in Apps Script - Google Docs

Looking through the Document Reference (found here ), I was unable to find any way to set the font weight of a Paragraph element.查看文档参考(在此处找到),我找不到任何方法来设置段落元素的字体粗细。

Is it even possible to do so?甚至有可能这样做吗?

Any help is appreciated.任何帮助表示赞赏。 Thanks in advance.提前致谢。

To adjust between normal and bold weights:在正常和粗体粗细之间进行调整:

  1. Use setAttributes and set DocumentApp.Attribute.BOLD to true or false (as @Tanaike alluded above).使用setAttributes并将DocumentApp.Attribute.BOLD设置为truefalse (如上面提到的@Tanaike)。
  2. Use setBold(bold) or setBold(startOffset, endOffsetInclusive, bold) .使用setBold(bold)setBold(startOffset, endOffsetInclusive, bold)

To set weights other than normal and bold for fonts that include additional weights (eg the medium weight of Alegreya Sans) there's an apparently undocumented method: use the setFontFamily(fontFamilyName) or setFontFamily(startOffset, endOffsetInclusive, fontFamilyName) method and append a semicolon and the numeric CSS font-weight to the font family string, like this: To set weights other than normal and bold for fonts that include additional weights (eg the medium weight of Alegreya Sans) there's an apparently undocumented method: use the setFontFamily(fontFamilyName) or setFontFamily(startOffset, endOffsetInclusive, fontFamilyName) method and append a semicolon and字体系列字符串的数字CSS 字体重量,如下所示:

someElement.setFontFamily('Alegreya Sans;500')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM