我想在第一个可用的免费行后将一个Google表格数据复制到其他Google表格。
function CopyDataToNewFile() {
var sss = SpreadsheetApp.openById('1vHc........'); // sss = source spreadsheet
var ss = sss.getSheetByName('Database'); // ss = source sheet
//Get full range of data
var SRange = ss.getDataRange();
//get A1 notation identifying the range
var A1Range = SRange.getA1Notation();
//get the data values in range
var SData = SRange.getValues();
var tss = SpreadsheetApp.openById('1ss......'); // tss = target spreadsheet
var ts = tss.getSheetByName('CalDatabase'); // ts = target sheet
ts.getRange(A1Range).setValues(SData);
}
上面的引用工作正常,但总是复制到同一行,但我希望它将数据复制到下面提供的新空白行。
试试这个 -
function CopyDataToNewFile() {
var sss = SpreadsheetApp.openById('1vHc........'); // sss = source spreadsheet
var ss = sss.getSheetByName('Database'); // ss = source sheet
var SData = ss.getDataRange().getValues();
var tss = SpreadsheetApp.openById('1ss......'); // tss = target spreadsheet
var ts = tss.getSheetByName('CalDatabase'); // ts = target sheet
ts.getRange(ts.getLastRow()+1,1,SData.length,SData[0].length).setValues(SData);
}