本文介绍了Google表格根据删除线(和背景颜色)对单元格进行计数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是对:
我需要稍作修改:
-只计算单元格,而不是条目
-just count cells, not entries
-如果细胞被剔除,则不要计数
-don't count a cell if it was struck-out
这是我的尝试,不起作用:
This was my attempt which doesn't work :
function totalColor(cells,color) {
const jsonColor = {
redberry: [ '#980000','#e6b8af','#dd7e6b','#cc4125','#a61c00','#85200c','#5b0f00'],
red: [ '#ff0000','#f4cccc', '#ea9999','#e06666','#cc0000','#990000','#660000' ],
orange:[ '#ff9900','#fce5cd','#f9cb9c','#f6b26b','#e69138','#b45f06','#783f04' ],
yellow: [ '#ffff00','#fff2cc','#ffe599','#ffd966','#f1c232','#bf9000','#7f6000' ],
green: [ '#00ff00','#d9ead3','#b6d7a8','#93c47d','#6aa84f','#38761d','#274e13' ],
cyan: [ '#00ffff','#d0e0e3','#a2c4c9','#76a5af','#45818e','#134f5c','#0c343d' ],
cornflowerblue: [ '#4a86e8','#c9daf8','#a4c2f4','#6d9eeb','#3c78d8','#1155cc','#1c4587' ],
blue:[ '#0000ff','#cfe2f3','#9fc5e8','#6fa8dc','#3d85c6','#0b5394','#073763' ],
purple: [ '#9900ff','#d9d2e9','#b4a7d6','#8e7cc3','#674ea7','#351c75','#20124d' ],
magenta: [ '#ff00ff','#ead1dc','#d5a6bd','#c27ba0','#a64d79','#741b47','#4c1130' ],
grey:["#666666", "#999999", "#b7b7b7", "#cccccc", "#d9d9d9", "#efefef", "#f3f3f3"],
white: ["#ffffff"],
black: ["#000000"]
};
const colorArr = jsonColor[color];
const sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
const range = sheet.getRange(cells);
const hex_array = range.getBackgrounds().flat();
const format_array = range.getFontLines().flat();
const values = range.getValues().flat();
Logger.log(format_array);
var total = 0;
hex_array.forEach((h,i,j)=>{
if(colorArr.includes(h) && format_array[j] != "line-through"){
total ++;
}
});
return total;
}
我还试图查看我实际在该阵列中放置的内容,但是Logger转到哪里,因为控制台窗口(Edge,F12和select console)中没有任何显示.
I also was trying to see what I was actually putting in that array, but where does the Logger go to as nothing shows in the console window (Edge, F12, select console).
推荐答案
您非常亲密.
在forEach()
方法中,您只能使用i
索引:
In the forEach()
method you must use only the i
index:
function totalColor(cells,color) {
const jsonColor = {
redberry: [ '#980000','#e6b8af','#dd7e6b','#cc4125','#a61c00','#85200c','#5b0f00'],
red: [ '#ff0000','#f4cccc', '#ea9999','#e06666','#cc0000','#990000','#660000' ],
orange:[ '#ff9900','#fce5cd','#f9cb9c','#f6b26b','#e69138','#b45f06','#783f04' ],
yellow: [ '#ffff00','#fff2cc','#ffe599','#ffd966','#f1c232','#bf9000','#7f6000' ],
green: [ '#00ff00','#d9ead3','#b6d7a8','#93c47d','#6aa84f','#38761d','#274e13' ],
cyan: [ '#00ffff','#d0e0e3','#a2c4c9','#76a5af','#45818e','#134f5c','#0c343d' ],
cornflowerblue: [ '#4a86e8','#c9daf8','#a4c2f4','#6d9eeb','#3c78d8','#1155cc','#1c4587' ],
blue:[ '#0000ff','#cfe2f3','#9fc5e8','#6fa8dc','#3d85c6','#0b5394','#073763' ],
purple: [ '#9900ff','#d9d2e9','#b4a7d6','#8e7cc3','#674ea7','#351c75','#20124d' ],
magenta: [ '#ff00ff','#ead1dc','#d5a6bd','#c27ba0','#a64d79','#741b47','#4c1130' ],
grey:["#666666", "#999999", "#b7b7b7", "#cccccc", "#d9d9d9", "#efefef", "#f3f3f3"],
white: ["#ffffff"],
black: ["#000000"]
};
const colorArr = jsonColor[color];
const sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
const range = sheet.getRange(cells);
const hex_array = range.getBackgrounds().flat();
const format_array = range.getFontLines().flat();
const values = range.getValues().flat();
var total = 0;
hex_array.forEach((h,i)=>{
if(colorArr.includes(h) && format_array[i] != "line-through"){
total ++;
}
});
return total;
}
这篇关于Google表格根据删除线(和背景颜色)对单元格进行计数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!