一般来说,.setValues(obj[][])要按预期工作Range,它所作用的 必须与obj[][].
通常,这是通过Range从所需的获取新的来确保的Sheet:
var ss = SpreadsheetApp.openById("some id");
var sheet = ss.getSheetByName("some name");
var db = sheet.getDataRange().getValues();
/*
* Do some operations on the obj[][] that is db
* these operations can include adding / removing rows or columns.
*/
// If db is smaller than existing "written" data, the existing data should be cleared first.
if(db.length < sheet.getLastRow() || db[0].length < sheet.getLastColumn())
sheet.clearContent();
// Write the current db back to the sheet, after acquiring the
// exact number of rows and columns needed to hold the values.
sheet.getRange(1, 1, db.length, db[0].length).setValues(db);