I would like to move data from one G-sheet to another not using importrange. How can I do this in Appscript?
CodePudding user response:
Use
var ssheet = SpreadsheetApp.openById(SPREADSHEET_ID)
var sheet = ssheet.getSheetByName(SHEET_NAME)
var values = sheet.getRange(RANGE_NOTATION).getValues()
and in your main sheet
var ssheet = SpreadsheetApp.getActiveSpreadsheet()
var sheet = ssheet.getSheetByName(SHEET_NAME)
sheet.getRange(RANGE_NOTATION).setValues(values)
then delete the original
CodePudding user response:
From the main sheet from where you want to extract data,use something like this :-
var ss = SpreadsheetApp.openById(ID_of_sheet) var ssname = ss.getSheetByName(Name_Of_that_particular_Sheet_in_theSpreadSheet) var DataCopied = ssname.getRange('A1:B').getValues() // "A1:B is an example StringNotation of that range from where you want to copy the data"
Now you have extracted the data from that sheet, use this to paste it on another sheet
var ss = SpreadsheetApp.openById(ID_of_Secondsheet) var ssname = ss.getSheetByName(Name_Of_that_particular_Sheet_in_theSpreadSheet) // where you want paste the data ssname.getRange('A1:B').setValues(DataCopied) // setValues will paste the data you copied.
Make sure to use the same rangeNotation which you've used while copying the data from main sheet. For more information, you can refer to documentation :- ServiceDoc