Reputation: 433
Is there any way i can insert multiple Rows into Google SpreadSheet without using any loops.
Need to do this task using google Apps Script only.
function testMultipleEntry(){
var sheet = SpreadsheetApp.openById(INSERT-SHEET-ID);
var mainSpreadSheet= sheet.getActiveSheet();
var fiveRows= mainSpreadSheet.getRange(2, 1, 5,mainSpreadSheet.getMaxColumns() );
var tempSheet= SpreadsheetApp.create("TestSheetAppend").getActiveSheet();
fiveRows.copyValuesToRange(tempSheet, 1, mainSpreadSheet.getMaxColumns(), 2, 5);//used the array[][]
}
last line is showing -- Service error: Spreadsheets
Upvotes: 1
Views: 4901
Reputation: 5186
I've spent some time looking into the official documentation on google app scripts, and based on that I can confirm you that there are many ways you can achieve this, one of which is explained below
Sample code
const startRowNumber = 1;
const starColumnNumber = 1;
const endRowNumber = dataToPut.length;
const endColumnNumber = dataToPut[0].length;
const range = sheet.getRange(startRowNumber, starColumnNumber, endRowNumber, endColumnNumber);
range.setValues(dataToPut);
Upvotes: 0
Reputation: 2143
I'm still not clear on what it is you're looking for, but this code takes data from one sheet, and inserts it into another one:
function enterData(){
var ss = SpreadsheetApp.openById('SHEET-ID');
var mainSheet= ss.getActiveSheet();
var fiveRows= mainSheet.getRange(2, 1, 5,mainSheet.getMaxColumns());
var createSheet= ss.insertSheet("TestSheetAppend");//This line will fail if a sheet by this name exists.
var tempSheet = ss.getSheetByName('TestSheetAppend');
fiveRows.copyValuesToRange(tempSheet, 1, tempSheet.getMaxColumns(), 2, 5);//used the array[][]
}
If you're looking to send it to another sheet entirely, you can modify this code to do so.
Upvotes: 3