假设我要清除列范围G2:GX
中找到的所有值,其中GX
对应于最后一个非空的单元格。
答案 0 :(得分:4)
function clearColumn(colNumber, startRow){
//colNumber is the numeric value of the colum
//startRow is the number of the starting row
var sheet = SpreadsheetApp.getActiveSheet();
var numRows = sheet.getLastRow() - startRow + 1; // The number of row to clear
var range = sheet.getRange(startRow, colNumber, numRows);
range.clear();
}
或者如果你想保留A1表示法:
function clearColumnA1Notation(a1Notation){
//a1Notation is the A1 notation of the first element of the column
var sheet = SpreadsheetApp.getActiveSheet();
var firstCell = sheet.getRange(a1Notation);
var numRows = sheet.getLastRow() - firstCell.getRow() + 1;
var range = sheet.getRange(firstCell.getRow(), firstCell.getColumn(), numRows);
range.clear();
}
对于您的示例,您可以使用:
clearColumn(7, 2);
或
clearColumnA1Notation("G2");
答案 1 :(得分:1)
sheet.getRange(“ G1:G”)。clear();
此语法将从G1清除列到最后一个可用的G列值。您想从第三行之间清除ID,然后可以使用
sheet.getRange(“ G3:G”)。clear();