Trying to copy a whole spreadsheet but I guess there is no api to do so.
Basically, I am trying to do the following:
Creating new spreadsheets works alright however, copying sheets from spreadsheet doesn't work.
Tried 2 ways:
Angular:
$http.post("https://sheets.googleapis.com/v4/spreadsheets/"+fromSpreadsheetId+"/sheets/"+fromSheetId,
{headers: {
'Authorization': 'Bearer ' + this.oauthToken
}},
Gives following error:
Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin'
Google Sheets Api call:
gapi.client.sheets.spreadsheets.sheets.copyTo({spreadsheetId: fromSpreadsheetId , sheetId: fromSheetId},{destinationSpreadsheetId: destinationSpreadsheetId});
Request goes through without any error. However, the newly created spreadsheet doesn't have the sheet copied.
You probably want to ask a separate question specifically for the CORS issue, since that a separate problem.
With regards to "copy a spreadsheet", you have two options:
1) Use the Drive API's files.copy method. The fileId
in the Drive API is equivalent to the spreadsheetId
in the Sheets API.
2) Don't use a "template" spreadsheet that you copy. Instead, use the Sheet API's spreadsheets.create method. You can use spreadsheets.get to retrieve your "template" JSON, and can tweak that as necessary before creating your new spreadsheet.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With