答案1
*编辑*
感谢您的澄清!以下是对脚本的一些快速编辑,使其在任意行和列的工作表上运行,使用中等粗细的黄色边框格式化最大值的单元格。快速拼凑起来,但我希望它能有所帮助!
function JKHAScript() {
//get the first sheet of the currently active google spreadsheet
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
var NumRows = sheet.getMaxRows();
var NumColumns = sheet.getMaxColumns();
//loop through each column skipping the first row, (j,i) is the (row#, column#)
for (let i = 1; i <= NumColumns; i++) {
var LargestCell = sheet.getRange(2,1);
for (let j = 2; j <= NumRows; j++) {
let IndexCell = sheet.getRange(j, i);
//one pass through each column, grabs the largest value
if (IndexCell.getValue() > LargestCell.getValue()) {
LargestCell = IndexCell;
}
}
//after pass, the cell with the largest value gets the border formatting
LargestCell.setBorder(true,true,true,true,null,null, "yellow", SpreadsheetApp.BorderStyle.SOLID_MEDIUM)
}
}
要在 Google 表格上运行脚本:打开表格,转到工具选项卡,单击脚本编辑器。仅将您信任的代码粘贴到编辑器中!!单击页面顶部的运行,即可在您当前打开的任何工作表上执行脚本。应该看起来像这样:
*原来的*
如果我误解了,请原谅我,但我相信你的问题可以通过以下方法解决谷歌应用脚本。我不确定您想要执行什么格式,但这里有一个简单的示例,可以在带有随机数字的 11 x 4 小表上运行。当然,您需要对其进行修改以在您的工作表上运行,并执行您希望应用的任何格式。
function JKHAScript() {
//get the first sheet of the currently active google spreadsheet
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
//loop through each column skipping the first row, (j,i) is the (row#, column#)
for (let i = 1; i <= 4; i++) {
var LargestCell = sheet.getRange(2,1);
for (let j = 2; j <=11; j++) {
let IndexCell = sheet.getRange(j, i);
//one pass through each column, grabs the largest value
if (IndexCell.getValue() > LargestCell.getValue()) {
LargestCell = IndexCell;
}
}
//after pass, the cell with the largest value gets the border formatting
LargestCell.setBorder(true,true,true,true,null,null, "yellow", null)
}
}
跑步前
跑步后
这是一个缓慢而蹩脚的例子。您可以在此处找到有关 Google 应用脚本的更多信息。祝你编写脚本顺利,我的朋友!