appendRows method
Appends rows with values from maps
.
Expands current sheet's size if inserting range is out of sheet's bounds.
maps
- list of maps containing values to insert (not null nor empty)
fromColumn
- optional (defaults to 1), column index for the first inserted
value,
columns start at index 1 (column A)
mapTo
- optional (defaults to 1), index of a row to which
keys of the maps
will be mapped to,
rows start at index 1
appendMissing
- optional (defaults to false
), whether keys of maps
(with its related values) that are not present in a mapTo
row
should be added
inRange
- optional (defaults to false), whether maps
values should be
appended to last row in range (respects fromColumn
) or last row in table
Returns Future true
in case of success.
Throws GSheetsException.
Implementation
Future<bool> appendRows(
List<Map<String, dynamic>> maps, {
int fromColumn = 1,
int mapTo = 1,
bool appendMissing = false,
bool inRange = false,
}) async {
checkIndex('fromColumn', fromColumn);
checkIndex('mapTo', mapTo);
checkMaps(maps);
final rows = await _values.allRows();
final row = inRange ? inRangeIndex(rows, fromColumn) + 1 : rows.length + 1;
if (row < 2) {
if (appendMissing && mapTo == 1) {
return _insertRows(
2,
maps,
<String>[],
fromColumn,
mapTo,
appendMissing,
false,
);
}
return false;
}
checkMapTo(column, mapTo);
if (mapTo > row) return false;
final keys = rows[mapTo - 1];
return _insertRows(
row,
maps,
keys,
fromColumn,
mapTo,
appendMissing,
false,
);
}