addFromSpreadsheet method
Copies Worksheet from another spreadsheet (the name of the copy will be "Copy of {title of copied sheet}").
spreadsheetId
- source spreadsheet id
sheetId
- id of the worksheet to copy
Provided credentialsJson
has to have permission to spreadsheetId
.
Returns Future Worksheet in case of success.
Throws GSheetsException.
Implementation
Future<Worksheet> addFromSpreadsheet(
String spreadsheetId,
int sheetId,
) async {
if (spreadsheetId.isEmpty || spreadsheetId == id) {
throw GSheetsException('invalid spreadsheetId ($spreadsheetId)');
}
final response = await _client.post(
'$_sheetsEndpoint$spreadsheetId/sheets/$sheetId:copyTo'.toUri(),
body: jsonEncode({'destinationSpreadsheetId': id}),
);
checkResponse(response);
final json = {'properties': jsonDecode(response.body)};
final ws = Worksheet._fromJson(
json,
_client,
id,
renderOption,
inputOption,
);
sheets.forEach((sheet) => sheet._incrementIndex(ws.index - 1));
sheets.add(ws);
return ws;
}