简体   繁体   English

是否可以在 Google Apps 脚本中迭代 ENUM?

[英]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.

相关问题 迭代 Google Apps 脚本中的对象 - Iterate over an object in Google Apps script 在Google Apps脚本中创建枚举ButtonSet - Creating a Enum ButtonSet in Google Apps Script 需要Google Apps脚本来遍历数组 - Need google apps script to iterate through an array Google 应用程序脚本 - 迭代文件夹和子文件夹 - Google apps script - iterate folder and subfolder 如何迭代Google Closure中的枚举值? - How do I iterate over enum values in Google Closure? 在Google Apps脚本中,如何让单个函数遍历跟踪多个不同变量对的数据结构? - In Google Apps Script, how can I have a single function iterate over a data structure that keeps track of many different pairs of variables? 是否可以在 Google Apps Script 上创建导航栏? - Is it possible to create navigation bar on Google Apps Script? Google Apps 脚本 FOR 循环无法使用嵌套的 IF 语句自动迭代 - Google Apps Script FOR Loop failing to automatically iterate with nested IF statements Google Apps 脚本:可以将 http 请求发送到不在互联网上的本地服务器吗? - Google Apps Script: Possible to send http requests to a local server that's not on interrnet? 迭代枚举,将enum枚举元素作为参数 - Iterate over enum, asign enum element as parameter
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM