有没有办法在 Google Apps 脚本中获取字符属性?

Is there a way to get the character properties in Google Apps Scripts?

我正在尝试获取文档中单个字符的 FOREGROUND_COLOR 值。我已经阅读了文档,到目前为止我还没有找到获得上述价值的方法。我明白文本 class 可以做到这一点;但是它只适用于大块文本,而不适用于单个字符。

您可以在文本元素上使用 getForegroundColor(offset) 并指定字符偏移以获得特定位置的颜色。参见 https://developers.google.com/apps-script/reference/document/text#getforegroundcoloroffset

例如:

var body = DocumentApp.getActiveDocument().getBody();
var content = body.editAsText();
Logger.log(content.getForegroundColor(7));

将给出文档中第 7 个字符的颜色。