我每天晚上都安排了一个脚本来查看许多不同的工作表并在任何新数据条目周围绘制边框。
该脚本有效但不一致。当我检查它完全适用于某些 google 表格和部分适用于其他表格时。每个 google 电子表格上大约有 10 个内部工作表,并且为某些人绘制了边框,而不为其他人绘制了边框。
我不明白为什么它运行不干净。
function addBorders() {
//Access the sheet which contains all the IDs
var idSheet = SpreadsheetApp.openById('example');
//Check for the last row
var lastRow = 0;
var currRow = 2;
//Loop through the sheet and find the last ID available
while (idSheet.getRange("A" + currRow).getValue() != "")
{
currRow = currRow + 1;
}
//Set the last row with an ID found to be the lastRow
lastRow = currRow;
idSheet.getRange("B1").setValue("Total Rows");
idSheet.getRange("B2").setValue(lastRow);
//Loop through the ID sheet to find the ID to make changes to
for( var y = 2; y < lastRow; y++)
{
var studentID = idSheet.getSheetByName("Sheet1").getRange(y, 1).getValue();
//As IDs are take from the ID sheet, open the relevant sheet and run the code below
var ss = SpreadsheetApp.openById(studentID);
var sheetsCount = ss.getNumSheets();
var sheets = ss.getSheets();
//For each sheet in the individal student spreadsheets, set the borders correctly
for (var i = 0; i < sheetsCount; i++)
{
var sheet = sheets[i];
var range = sheet.getRange(6, 3, 35);
var values = range.getValues().map(function(d){ return d[0] });
//clear previous border
var selection = sheet.getRange(6,2,35,5)
selection.setBorder(false,false,false,false,false,false);
//set border
var index = values.indexOf("");
var border = sheet.getRange(5, 2, index+1, 5);
border.setBorder(true, true, true, true, true, true);
}
}
}