[英]Is it possible to iterate over ENUM's in Google Apps Script?
I would like to get all available Font-families in a Google Apps Script for Google Docs.我想在 Google Docs 的 Google Apps 脚本中获取所有可用的字体系列。 FontFamilies are defined as FontFamily ENUM. FontFamilies 定义为 FontFamily ENUM。 Can I iterate over this ENUM to get all the possible FontFamilies in this document?我可以遍历这个 ENUM 来获取这个文档中所有可能的 FontFamilies 吗?
UPDATE: I have found my own answer:更新:我找到了自己的答案:
var fontfamilies = DocumentApp.FontFamily.values();
for(var i in fontfamilies){
Logger.log(fontfamilies[i]);
}
So to answer my own question (I guess to have it show as an answer I can't just edit my original question), Google Apps ENUM's do have a "values()" property / method just like in Java.因此,为了回答我自己的问题(我想将它显示为答案,我不能只编辑我的原始问题),Google Apps ENUM 确实有一个“values()”属性/方法,就像在 Java 中一样。 It will give an array with the ENUM values, in this case the names of the font families defined in the FontFamily ENUM.它将给出一个包含 ENUM 值的数组,在这种情况下是 FontFamily ENUM 中定义的字体系列的名称。
Here is an example code to iterate over these values:以下是迭代这些值的示例代码:
var fontfamilies = DocumentApp.FontFamily.values();
for(var i in fontfamilies){
Logger.log(fontfamilies[i]);
}
UPDATE april 2020: It seems that the FontFamily ENUM has been deprecated , and currently there is no way to retrieve an array of font family names for font families that are currently available to the document. 2020 年 4 月更新:似乎 FontFamily ENUM 已弃用,目前无法检索文档当前可用的字体系列的字体系列名称数组。 I have opened an issue on the issue tracker , please star if you would appreciate this functionality.我在问题跟踪器上打开了一个问题,如果您喜欢这个功能,请加星号。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.