这里有四个功能:(1) 设置值的水平范围 (2) 设置值的垂直范围 (3) 设置值的区域 (4) 复制值的区域并粘贴。
function SetHorizontalRange() {
var Spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
var Sheet = Spreadsheet.getActiveSheet();
var row = 1; var numRows = 1;
var column = 1; var numColumns = 3; //("A1:C1")
var Range = Sheet.getRange(row, column, numRows, numColumns)
var values = [[["Adam"],["Barb"],["Chris"]]];
Range.setValues(values)
}
//////////////////////////////////////////////////////////////////////////////ℱℳ
function SetVerticalRange() {
var Spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
var Sheet = Spreadsheet.getActiveSheet();
var row = 1; var numRows = 3;
var column = 1; var numColumns = 1; //("A1:A3")
var Range = Sheet.getRange(row, column, numRows, numColumns)
var values = [["Adam"],["Barb"],["Chris"]];
Range.setValues(values)
}
//////////////////////////////////////////////////////////////////////////////ℱℳ
function SetArea(){
var Spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
var Sheet = Spreadsheet.getActiveSheet();
var row = 1; var numRows = 3;
var column = 1; var numColumns = 3; //("A1:C3")
var Range = Sheet.getRange(row, column, numRows, numColumns)
var values = [[[["Adam"]], [["Barb"]], [["Chris"]]], [[["Barb"]], [["Chris"]], [["Adam"]]], [[["Chris"]], [["Adam"]], [["Barb"]]]];
Range.setValues(values)
}
//////////////////////////////////////////////////////////////////////////////ℱℳ
function CopyPasteArea(){
var Spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
var Sheet = Spreadsheet.getActiveSheet();
var row = 1; var column = 1;
var Range = Sheet.getRange(row, column);
var values = new Array(3);
for (var y = 0; y < 3; y++) {
values[y] = new Array(3);
for (var x = 0; x < 3; x++) {
values[y][x] = Range.offset(x,y).getValues(); Logger.log(x+' '+y);
}
}
Sheet.getRange(4, 1, 3, 3).setValues(values); Logger.log(values)
//https://developers.google.com/apps-script/best_practices
}