google-apps-script - Google Apps Script: Color a table cell on the Google Slide, based on the value of a cell on the Google Sheets
问题描述
I'm reading rows from a google sheet and creating a slide for each of them on the google slides. To do this, I use a template slide which is the first slide, which has placeholders for each column's value on the slide.
While I've been able to achieve getting the data on the sheet, I want to dynamically set the background color of a table I have on my slide, based on the value it gets populated with.
For instance, I have a table column named "Priority" and it can have values "Low", "Medium", and "High". I want the background color to be Green, Orange and Red based on these values. I can't set this background color in the template slide, as that would make all the values have the same color. I'm looking for a way to dynamically color this specific cell of this specific table on my slide, and I have multiple tables on my slide. I also need a way to identify my target table.
I'm looking through the documentation Google Apps Script provides, but I haven't quite been able to narrow down what API it is exactly, that I need to achieve this. I've looked into Slide>Table Class, and while there are some APIs that could like get the table, get the cell, etc., I don't see anything that could help me achieve my use case.
//Ideally, this is how it would work if I had the API:
//Pseudocode below:
let myTableIdentifier = "FooBar"; //How do I get this identifier which tells one table apart from another on your slide?
let tables = mySlide.getTables();
let myTargetTable = tables.get(myTableIdentifier); //Not sure if this is possible, getting a table based on some identifier.
let incomingValue = "High";
let backgroundColor = _colorPicker(incomingValue); //Assume this function gets me the color name, like "Red".
myTargetTable.getCell("Priority").setBackgroundColor(backgroundColor);
What am I missing here? Can this even be done with the APIs already available?
解决方案
推荐阅读
- c# - 有没有办法清除服务器端 OWIN / 身份验证数据?
- reactjs - 如何在 react-native 中获取单独的数组文件名“info.js”的值
- php - 使用 PHP 中的变量访问 const
- javascript - 如何使用moment js获取开始日期和结束日期之间的日期列表
- sap - 取消隐藏 ALV 网格中的列
- vue.js - Vue组件Vuex选项块功能
- java - Derby - java.sql.SQLException:找不到列'table.column_name'
- r - 使用 dplyr 过滤连接的多个条件
- python - 如何连接到现有的 Jupyter Notebook 内核并使用变量资源管理器检查变量?
- javascript - 使用javascript在不使用jquery的情况下删除焦点事件的文本框的css类