addWorksheet method
Adds new Worksheet with specified title
, rows
and columns
.
title
- title of a new Worksheet.
rows
- optional (defaults to 1000), row count of a new Worksheet.
columns
- optional (defaults to 26), column count of a new Worksheet.
Returns Future of created Worksheet.
Throws GSheetsException if sheet with title
already exists, or
if rows
or columns
value is invalid.
Implementation
Future<Worksheet> addWorksheet(
String title, {
int rows = defaultRowsCount,
int columns = defaultColumnCount,
}) async {
checkIndex('columns', columns);
checkIndex('rows', rows);
final response = await GSheets.batchUpdate(_client, id, [
{
'addSheet': {
'properties': {
'title': title,
'sheetType': 'GRID',
'gridProperties': {
'rowCount': rows,
'columnCount': columns,
}
},
}
}
]);
final addSheetJson = (jsonDecode(response.body)['replies'] as List?)?.first;
final ws = Worksheet._fromJson(
addSheetJson['addSheet'],
_client,
id,
renderOption,
inputOption,
);
sheets.forEach((sheet) => sheet._incrementIndex(ws.index - 1));
sheets.add(ws);
return ws;
}