lastColumn method
Fetches last column, maps it to other column and returns map.
Expands current sheet's size if requested range is out of sheet's bounds.
fromRow
- optional (defaults to 1), index of a row that requested column
starts from (values before fromRow
will be skipped),
rows start at index 1
length
- optional (defaults to -1), the length of a requested column
if length is -1
, all values starting from fromRow
will be returned
mapTo
- optional (defaults to 1), index of a column to map values to
(keys of returned map),
columns start at index 1 (column A)
inRange
- optional (defaults to false), whether should be fetched last
column in range (respects fromRow
and length
) or last column in table
Returns column as Future Map of String to String.
Returns Future null
if there are less than 2 columns.
Throws GSheetsException.
Implementation
Future<Map<String, String>?> lastColumn({
int fromRow = 1,
int length = -1,
int mapTo = 1,
bool inRange = false,
}) async {
checkIndex('mapTo', mapTo);
if (inRange) {
final columns = await _values.allColumns(
fromRow: fromRow,
length: length,
);
if (columns.length < 2) return null;
checkMapTo(columns.length, mapTo);
final column = columns.length;
final keys = get(columns, at: mapTo - 1, or: <String>[])!;
final values = get(columns, at: column - 1, or: <String>[])!;
return _wrap(keys, values);
} else {
checkIndex('fromRow', fromRow);
final columns = await _values.allColumns();
if (columns.length < 2) return null;
checkMapTo(columns.length, mapTo);
final column = columns.length;
final keys = extractSublist(
get(columns, at: mapTo - 1, or: <String>[])!,
from: fromRow - 1,
length: length,
);
final values = extractSublist(
get(columns, at: column - 1, or: <String>[])!,
from: fromRow - 1,
length: length,
);
return _wrap(keys, values);
}
}