将变量作为DocumentApp.Attribute.FONT_SIZ传递

时间:2012-05-10 14:22:01

标签: google-apps-script

我希望能够允许我的用户为他们正在创建的文档指定字体大小(和系列)。我有一个他们在配置页面上选择的各种大小的列表框,但我不确定如何将它分配给代码。例如,这很好用:

'var lHeading2style = {};   lHeading2style [DocumentApp.Attribute.FONT_FAMILY] = DocumentApp.FontFamily.headingStyle2font;    lHeading2style [DocumentApp.Attribute.FONT_SIZE] = 14;    lHeading2style [DocumentApp.Attribute.BOLD] = false;'

但是,如果我按如下所示设置变量,如何将其附加到我的代码行?

var headingStyle3FontSize ='8';

var lHeading3style = {}; lHeading3style [DocumentApp.Attribute.FONT_FAMILY] = DocumentApp.FontFamily + headingStyle3font;    lHeading3style [DocumentApp.Attribute.FONT_SIZE] =' headingStyle3FontSize ';    lHeading3style [DocumentApp.Attribute.BOLD] = false; //格式化样式

我也试过了    lHeading3style [DocumentApp.Attribute.FONT_SIZE] = headingStyle3FontSize ;

感谢您的帮助!

1 个答案:

答案 0 :(得分:1)

您应该为变量使用数字值,而不是字符串值。

var headingStyle3FontSize = 8;
lHeading3style[DocumentApp.Attribute.FONT_SIZE] = headingStyle3FontSize;