appendColumns method
Appends columns 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)
fromRow
- optional (defaults to 1), row index for the first inserted value,
rows start at index 1
mapTo
- optional (defaults to 1), index of a column to which
keys of the maps
will be mapped to,
columns start at index 1 (column A)
appendMissing
- optional (defaults to false
), whether keys of maps
(with its related values) that are not present in a mapTo
column
should be added
inRange
- optional (defaults to false), whether maps
values should be
appended to last column in range (respects fromRow
) or last column in table
Returns Future true
in case of success.
Throws GSheetsException.
Implementation
Future<bool> appendColumns(
List<Map<String, dynamic>> maps, {
int fromRow = 1,
int mapTo = 1,
bool appendMissing = false,
bool inRange = false,
}) async {
checkIndex('fromRow', fromRow);
checkIndex('mapTo', mapTo);
checkMaps(maps);
final columns = await _values.allColumns();
final column =
inRange ? inRangeIndex(columns, fromRow) + 1 : columns.length + 1;
if (column < 2) {
if (appendMissing && mapTo == 1) {
return _insertColumns(
2,
maps,
<String>[],
fromRow,
mapTo,
appendMissing,
false,
);
}
return false;
}
checkMapTo(column, mapTo);
if (mapTo > column) return false;
final keys = columns[mapTo - 1];
return _insertColumns(
column,
maps,
keys,
fromRow,
mapTo,
appendMissing,
false,
);
}