0
假設我想清除在列範圍G2:GX
中找到的所有值,其中GX
對應於最後一個非空的單元格。如何使用Google Apps腳本清除Google表格中的列?
假設我想清除在列範圍G2:GX
中找到的所有值,其中GX
對應於最後一個非空的單元格。如何使用Google Apps腳本清除Google表格中的列?
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");