google-apps-script - Google 电子表格中带有条件格式的色阶

标签 google-apps-script google-sheets google-docs gs-conditional-formatting

我需要在 Google 电子表格中的行或列上使用色标,例如 Microsoft Office 提供的色标 Excel conditional formatting with color scale :

Color scale within Conditional Formatting in Microsoft 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++;
  }
}
  • 有没有办法在本地做到这一点?
  • 或者是否有任何谷歌应用程序脚本可以做到这一点(我忽略了)?
  • 或者有人愿意帮我把我的伪代码带到一个合适的地方
    电子表格的谷歌应用程序脚本?

  • 谢谢

    最佳答案

    Google 表格现在支持菜单“格式 > 条件格式...”下的条件色阶,然后选择“色阶”选项卡。

    Google Sheets color scale

    关于google-apps-script - Google 电子表格中带有条件格式的色阶,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19637514/

    相关文章:

    javascript - 删除 Google 表格中的重复行,忽略单元格的顺序

    javascript - 如何在谷歌应用程序脚本中按文件路径过滤

    javascript - Google 表格/Apps 脚本将公式复制到新行

    google-sheets - ArrayFormula IF ROW 不为空然后遍历公式

    excel - Google Docs 电子表格中基于规则的自动填充

    java - 如何在 Android 中使用 Google 表单

    google-apps-script - 如何使用谷歌应用程序脚本访问子文件夹?

    google-sheets - 在 Google 表格中多次重复一系列项目

    javascript - 添加行并保持格式 - Google 表格

    google-apps-script - 使用 Google Apps Script 将标题样式应用于单词的所有实例