javascript - 计算合并单元格时,按背景颜色计算行数失败——google sheet
问题描述
嘿伙计们,我在 google sheet excel 中,我想计算有多少行有基于背景颜色的合并单元格。
我使用 ScriptEditor 来解决它。我有下一个代码:
function countColoredCells(countRange,colorRef) {
var activeRg = SpreadsheetApp.getActiveRange();
var activeSht = SpreadsheetApp.getActiveSheet();
var activeformula = activeRg.getFormula();
var countRangeAddress = activeformula.match(/\((.*)\,/).pop().trim();
var backGrounds = activeSht.getRange(countRangeAddress).getBackgrounds();
var colorRefAddress = activeformula.match(/\,(.*)\)/).pop().trim();
var BackGround = activeSht.getRange(colorRefAddress).getBackground();
var countCells = 0;
for (var i = 0; i < backGrounds.length; i++)
for (var k = 0; k < backGrounds[i].length; k++)
if ( backGrounds[i][k] == BackGround )
countCells = countCells + 1;
return countCells;
};
有效,</p>
但如果我合并一些单元格,它就不起作用。
我想要的是按背景颜色计算每个合并单元格块的行数。
解决方案
推荐阅读
- r - 左对齐在 Markdown html 输出文档 R 中不起作用
- python - micropython - ESP32 - MQTT 异常 4 - 谷歌云物联网
- javascript - 使用现有接口扩展接口
- javascript - 为什么我的元素没有出现?
- python - 如何使用 Python 查找 Word 文档的页数?
- java - 将第一个数组元素与最后一个交换,第二个与倒数第二个交换,依此类推
- python - 如何根据 django rest framefork 中的用户角色返回嵌套数据?
- numpy - 高级 numpy 布尔索引
- kubernetes - apply 是否根据滚动更新策略工作?
- javascript - 当我想给元素随机绝对位置时,如何防止元素重叠