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 (cells 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 cells starting from fromRow
will be returned
mapTo
- optional (defaults to 1), index of a column to map cells 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 Cell.
Returns Future null
if there are less than 2 columns.
Throws GSheetsException.
Implementation
Future<Map<String, Cell>?> lastColumn({
int fromRow = 1,
int mapTo = 1,
int length = -1,
bool inRange = false,
}) async {
checkIndex('mapTo', mapTo);
if (inRange) {
final columns = await _cells._ws.values.allColumns(
fromRow: fromRow,
length: length,
);
final column = columns.length;
if (column < 2) return null;
checkMapTo(column, mapTo);
final keys = get(columns, at: mapTo - 1, or: <String>[])!;
final values = columns[column - 1];
return _wrapColumn(keys, values, column, fromRow);
} else {
checkIndex('fromRow', fromRow);
final columns = await _cells._ws.values.allColumns();
final column = columns.length;
if (column < 2) return null;
checkMapTo(column, mapTo);
final keys = extractSublist(
get(columns, at: mapTo - 1, or: <String>[])!,
from: fromRow - 1,
length: length,
);
final values = extractSublist(
columns[column - 1],
from: fromRow - 1,
length: length,
);
return _wrapColumn(keys, values, column, fromRow);
}
}