I have a spreadsheet that I would like to create an app script function to clear data/set values from certain cells. It also needs to work up to the last row, as I will be adding many rows. I have something started but it also wipes the header row. I would like, as I say, to be able to reset a bunch of cells however many rows there are, but preserving the header.
代码:
function clear() {
var header = SpreadsheetApp.getActive()
.getRangeList(['1:1']);
var rangeList1 = SpreadsheetApp.getActive()
.getRangeList(['I:I', 'J:J','L:L', 'N:N', 'O:O', 'P:P']);
rangeList1.setValue("-");
var rangeList2 = SpreadsheetApp.getActive()
.getRangeList(['C:C', 'D:D', 'G:G', 'H:H', 'M:M', 'R:R', 'S:S', 'T:T']);
rangeList2.setValue(" ");
}
I have a function written that defines ranges based on the columns, some to be reset to '-' some to be reset to ' ' (blank)
The problem is when I run the script the correct values are placed in the correct columns, but the header is also changed. I would like to preserve or protect the header. (菜单栏中的菜单项也被激活的脚本btw)
我尝试使用.offset,但我无法正确获得语法。我做到了
获取所有数据
检查该纸中存在多少个单元function clear(sheet, headerSize = 0) {
const nRows = sheet.getMaxRows(); // number of rows on the sheet
const nColumns = sheet.getMaxColumns(); // number of columns on the sheet
const lastCell = sheet.getRange(nRows, nColumns); // the last cell of this sheet
// get the cells from the row just below the header
// from the first to the last column
const data = sheet.getRange('A' + (headerSize + 1) + ':' + lastCell.getA1Notation());
data.clear();
}
// clear all cells leaving the header (first row) as it is
const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(SHEETNAME));
const headerSize = 1;
clear(sheet, headerSize);