Google Apps 脚本:TableChart - 如何使用 cssClassNames
我正在尝试修改已添加到 Google 幻灯片的表格图表的格式。
我发现 setOption
将是用于实现此目的的函数,但我无法验证是否可以修改以下属性:
- 标题颜色
- 文本对齐
- 文本环绕:环绕
此 < a href="https://developers.google.com/apps-script/reference/charts/table-chart-builder#setOption(String,Object)" rel="nofollow noreferrer">参考 表明我们有以下配置选项位于此处。
其中 cssClassNames 被提到为
一个对象,其中每个属性名称描述一个表元素,并且 属性值是一个字符串
我尝试将其应用到我的代码中:
function TablesConstructor(){
//slide_obj is an object that contains all the information needed.
//Let's open the file
var slide_file = SlidesApp.openById("your_slide_id");
//Get the Slides
var slides = slide_file.getSlides();
var slide_elements = slides[0].getPageElements();
//Create Data Table chart
var table_data = Charts.newDataTable()
.addColumn(Charts.ColumnType.NUMBER, "Col1")
.addColumn(Charts.ColumnType.NUMBER, "Col2")
.addColumn(Charts.ColumnType.NUMBER, "Col3")
.addColumn(Charts.ColumnType.NUMBER, "Col4")
//Populate data table chart with the 2D array inside my object
for(var i = 0; i < 4; i++){
table_data.addRow([(i + 1),
(i + 2),
(i + 3),
(i + 4),
);
}
var cssClassNames = {
headerRow: 'italic-darkblue-font large-font bold-font'
};
//Build the table
var table_chart = Charts.newTableChart()
.setOption('cssClassNames', cssClassNames)
.useAlternatingRowStyle(false)
.setDataTable(table_data)
.setDimensions(720, 480).build();
slide_elements[0].asShape().replaceWithImage(table_chart.getAs('image/jpeg'));
slide_file.saveAndClose();
}
How should the cssClassNames 参数用于更改其文本颜色、背景颜色?它看起来与我所知道的常规 CSS 有点不同。或者有其他方法可以修改表格格式吗?
I'm trying to modify the format of the Table Chart that I've added to a Google Slide.
I've found that the setOption
would be the function to use to achieve this but I haven't been able to validate if the following attributes can be modified:
- Header color
- Text Alignment
- Text Wrapping: Wrap
This reference indicates that we have the following configuration options here.
In there cssClassNames gets mentioned as
An object in which each property name describes a table element, and
the property value is a string
I've tried to apply that to my code:
function TablesConstructor(){
//slide_obj is an object that contains all the information needed.
//Let's open the file
var slide_file = SlidesApp.openById("your_slide_id");
//Get the Slides
var slides = slide_file.getSlides();
var slide_elements = slides[0].getPageElements();
//Create Data Table chart
var table_data = Charts.newDataTable()
.addColumn(Charts.ColumnType.NUMBER, "Col1")
.addColumn(Charts.ColumnType.NUMBER, "Col2")
.addColumn(Charts.ColumnType.NUMBER, "Col3")
.addColumn(Charts.ColumnType.NUMBER, "Col4")
//Populate data table chart with the 2D array inside my object
for(var i = 0; i < 4; i++){
table_data.addRow([(i + 1),
(i + 2),
(i + 3),
(i + 4),
);
}
var cssClassNames = {
headerRow: 'italic-darkblue-font large-font bold-font'
};
//Build the table
var table_chart = Charts.newTableChart()
.setOption('cssClassNames', cssClassNames)
.useAlternatingRowStyle(false)
.setDataTable(table_data)
.setDimensions(720, 480).build();
slide_elements[0].asShape().replaceWithImage(table_chart.getAs('image/jpeg'));
slide_file.saveAndClose();
}
How should the cssClassNames
parameter be used to change its text color, background color? It looks a little different than the regular CSS I know. Or is there another method to modify the table format?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
设置
cssClassNames
的方法似乎是正确的,并且在典型的 html 示例中工作正常,如下所示...
只需确保您的 css 在页面上的某个位置可用...
the method for setting
cssClassNames
appears to be correct,and works fine in a typical html example, as follows...
just make sure your css is available somewhere on the page...