Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Color scale with conditional formatting in Google Spreadsheet

I need a color scale on a row or column in Google Spreadsheet, like the one provided by Microsoft Office Excel conditional formatting with color scale:

Color scale within Conditional Formatting in Microsoft Excel

I couldn't find a Google Script Gallery Script that can do exactly this job. Setting conditional formatting manually for all possible values is not a solution.

My abilities are limited to write a proper script. Therefore I came up with this pseudo code:

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++;
  }
}
  • Is there any way to do it natively?
  • or are there any google app scripts that do this (which I overlooked)?
  • or is someone willing to help me bring my pseudo-code to a proper google app script for spreadsheet?

Thanks

like image 408
Underlines Avatar asked Oct 28 '13 14:10

Underlines


People also ask

How do you use conditional formatting color scales?

Format cells by using color scales Select the range of cells, the table, or the whole sheet that you want to apply conditional formatting to. On the Home tab, under Format, click Conditional Formatting. Point to Color Scales, and then click the color scale format that you want.

How do you make a color scale in Google Sheets?

Select the cells, click Format > Conditional Formatting from the menu, and confirm the cell range in the sidebar. Click the color scale below Preview and this time, choose “Custom Color Scale” at the bottom.


1 Answers

Google Sheets now supports conditional color scales under Menu "Format > Conditional formatting..." then select the tab "Colour scale".

Google Sheets color scale

like image 76
Underlines Avatar answered Sep 23 '22 09:09

Underlines