我需要在Google电子表格中的行或列上使用色标,就像Microsoft Office Excel条件格式提供的色标一样:
我找不到可以完成这项工作的Google Script Gallery脚本.手动为所有可能的值设置条件格式不是解决方案.
我的能力仅限于写一个合适的剧本.因此我想出了这个伪代码:
colorRangeFormatting(cellRange, minColorHex, maxColorHex)
{
float cellValueMax = getHighestValue(cellRange);
float cellValueMin = getLowestValue(cellRange);
int cellCount = range.length;
int colorValueMax = maxColorHex.toInt();
int colorValueMin = minColorHex.toInt();
int colorSize = colorValueMax - colorValueMin;
cellValueSize = cellValueMax - celLValueMin;
int colorIncrement = (colorSize/cellValueSize).Round();
int[] colorGradients = colorGradients[colorSize];
foreach(int color in colorGradients)
{
color = colorValueMin + colorIncrement;
colorIncrement = colorIncrement + colorIncrement;
}
int i = 0;
foreach(Cell c in cellRange)
{
c.setBackgroundColor(colorGradients[i].ToHex());
i++;
}
} …
Run Code Online (Sandbox Code Playgroud) google-docs google-sheets google-apps-script gs-conditional-formatting