Here are my dotfiles.
cd ~/.config
git clone https://github.com/clupasq/clupasq.git
cd clupasq
./setup.sh
allow summing up cells depending on their foreground/background color in Google Spreadsheets
License: MIT License
Is there a way to count background
or foreground
cells with your script?
Like a few others that created issues, i was under the impression that it would add the total of cells w/ the specified color given (without a number present or not).
I'm looking for something like this:
countWhereBackgroundColorIs(<color>, <range specification>, [<spreadsheet key>])
or
countWhereForegroundColorIs(<color>, <range specification>, [<spreadsheet key>])
After coming across your code on stackoverflow, it looks like this is exactly what I need. I was pretty excited to try it out as it would help me simplify my spreadsheet
So I set it up, used the "getBackgroundColor" function with "" around the cell number, and it pulls the color code (in this case #ff0000 or #b7b7b7). However, when I use the "sumWhereBackgroundColorIs("#ff0000","B3:B500", "", "B3:B500")" it responds with 0 cells holding that color, even though I have in B3 that is being used by getBackgroundColor to let me know at hex code to check for.
I really do think this would do exactly what I am hoping for. I tried using the Google Scripts debugger, but it isn't incredibly helpful in this situation (as it expects there to be a range of something, and there isn't one).
This script works great and it would be lovely if it provided count functionality as well.
In a case where I needed that, I added the following two functions:
function countWhereBackgroundColorIs(color, rangeSpecification, key) {
var condition = function (cell) { return cell.getBackground().toLowerCase() == color.toLowerCase(); };
return countByCondition(rangeSpecification, condition, key);
}
/**
* Counts number of occurrences in the given range that have a
* specific condition.
*
* @param {rangeSpecification} rangeSpecification - the range to search against.
* @param {condition} condition - a function that determines if the cell should be
* counted or not.
* @param {key} key (optional) - the key of a remote spreadsheet. If provided the
* range lookup will be done remotely.
* @return A count of matching cells.
* @customfunction
*/
function countByCondition(rangeSpecification, condition, key) {
var sheet = _getSpreadsheet(key);
var range = sheet.getRange(rangeSpecification);
var count = 0;
for (var i = 1; i <= range.getNumRows(); i++) {
for (var j = 1; j <= range.getNumColumns(); j++) {
var cell = range.getCell(i, j);
if(condition(cell)) {
count++;
}
}
}
return count;
}
To add it properly the following is needed:
I have been using these functions for quite some time. Today the functions are behaving inappropriately and shows 0 for all the sums even for my older sheets. Not sure if this is because of some updates from google sheets or what...
For some reason update trick is not working as desribed. Have there been any changes in the script?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.