2017-08-08 122 views

回答

2

Range.clear() method看看:

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"); 
相關問題