javascript - 用于在 Google doc 中为当前选择设置字体的 Apps 脚本
问题描述
我有一些 Google Apps 脚本代码来设置 Google 文档中某些文本的字体。
text.setFontFamily(element.getStartOffset(), element.getEndOffsetInclusive(), "Roboto Mono");
但我想要 Roboto Mono Medium。我该怎么做呢?我不确定是什么样的实体媒体。我认为这是一个重量。但我没有看到任何记录的方式来设置权重。
解决方案
当我通过给出“Roboto Mono Medium”检查字体名称时,它是“Roboto Mono;500”。那么如何使用Roboto Mono;500
如下的字体名称呢?
从:
text.setFontFamily(element.getStartOffset(), element.getEndOffsetInclusive(), "Roboto Mono");
到:
text.setFontFamily(element.getStartOffset(), element.getEndOffsetInclusive(), "Roboto Mono;500");
笔记:
检查字体名称的简单示例脚本如下。当您使用它时,请将脚本复制并粘贴到 Google Document 的脚本编辑器中,并在正文中选择一个文本并运行该脚本。
const selection = DocumentApp.getActiveDocument().getSelection(); const text = selection.getSelectedElements()[0].getElement().asText(); console.log(text.getFontFamily()) // Check the font name.
推荐阅读
- c++ - OpenSSL DER ECDSA 编码错误
- .net - 在没有 GAC 的 WMI 类中引用第 3 方 .dll
- c - 在多个 cython 模块上共享全局 c 变量
- ios - 多个故事板:它们应该有多小?
- c++ - VS 2017 - 带有版本信息(资源)的 C++ DLL 的 MSBuild 不起作用(致命错误 LNK1158:无法运行“cvtres.exe”)
- python - 我无法理解 keras 中的 skipgrams() 函数
- vba - 运行时错误 91 对象变量或未设置变量
- python - 如何设置numpy并行度?
- c# - C# Make Tree Node text 可下载链接
- java - java中带有hibernate的通用dao