ors*_*iro 4 google-sheets google-apps-script
假设我想清除G2:GX在GX与最后一个非空单元格相对应的列范围中找到的所有值。
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();
}
Run Code Online (Sandbox Code Playgroud)
或者如果你想保留 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();
}
Run Code Online (Sandbox Code Playgroud)
对于您的示例,您可以使用:
clearColumn(7, 2);
Run Code Online (Sandbox Code Playgroud)
或者
clearColumnA1Notation("G2");
Run Code Online (Sandbox Code Playgroud)
sheet.getRange("G1:G").clear();
此语法将清除从 G1 到最后一个可用 G 列值的列。如果你想从第三行之间清除它,那么你可以使用
sheet.getRange("G3:G").clear();
| 归档时间: |
|
| 查看次数: |
11728 次 |
| 最近记录: |