根据彩色单元格更新单元格的值 - Google文档电子表格 [英] Update a cell's value according to colored cells - Google Docs Spreadsheet
本文介绍了根据彩色单元格更新单元格的值 - Google文档电子表格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在Google文档电子表格中,我有一些单元格为绿色和红色。我想要一个具有这些绿/红色细胞计数的单元格。
In Google Docs spreadsheet, I have some cells green and red colored. I want a cell having the count of those green/red colored cells.
我可以有一个公式来做这个事情吗?
Can I have a formula to do this thing or any custome code for this?
推荐答案
这个 Google Apps脚本应该开始(请参阅示例电子表格):
This Google Apps Script should get you started (see example spreadsheet):
function countRedBackgrounds() {
var COUNT_RED = 0;
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Cell colors");
var dataRange = sheet.getDataRange();
for (var i = 1; i<dataRange.getNumRows(); i++) {
for (var j = 1; j<dataRange.getNumColumns(); j++) {
if (dataRange.getCell(i,j).getBackground() == "#ff0000")
COUNT_RED++;
}
}
dataRange.getCell(1,1).setValue(COUNT_RED);
}
这篇关于根据彩色单元格更新单元格的值 - Google文档电子表格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文