我正在尝试编写一个脚本,该脚本可以找到特定列(给定数据集中的比例列)中的最大值并相应地突出显示单元格。
下面是我目前所在的位置
function myFunction() {
var ss = SpreadsheetApp.getActive();
var sh = ss.getSheetByName('Sheet1');
var range = sh.getRange("G2:G17");
var values = range.getValues();
var newRange = SpreadsheetApp.getActiveSheet().getRange(2, 7, values.length, 1).getValues();
var maximumproportion = Math.max.apply(Math, newRange);
var maxarr = [];
maxarr.push(maximumproportion)
var backgrounds = [];
var fontColors = [];
range.sort([{column:7, ascending: false}]); // sort by number is column 7
if (newRange === maxarr) {
backgrounds.push(["green"])
}else{
backgrounds.push([null])
}
SpreadsheetApp.getActiveSheet().getRange(2,7,values.length,1).setBackgrounds(backgrounds);
}
Run Code Online (Sandbox Code Playgroud)
因此,如果上面的代码正常工作,它应该突出显示最后一列中的第一行,即 0.27%,因为这是此列中找到的最大值。
对于下面的部分,我还尝试使用 for 循环。但没有运气
有人可以建议我如何才能完成这项工作吗?
// find the max value in …Run Code Online (Sandbox Code Playgroud)