selectRange method
returns 2-D dynamic List
of the sheet cell data in that range.
Implementation
List<List<Data?>?> selectRange(CellIndex start, {CellIndex? end}) {
_checkMaxCol(start.columnIndex);
_checkMaxRow(start.rowIndex);
if (end != null) {
_checkMaxCol(end.columnIndex);
_checkMaxRow(end.rowIndex);
}
int _startColumn = start.columnIndex, _startRow = start.rowIndex;
int? _endColumn = end?.columnIndex, _endRow = end?.rowIndex;
if (_endColumn != null && _endRow != null) {
if (_startRow > _endRow) {
_startRow = end!.rowIndex;
_endRow = start.rowIndex;
}
if (_endColumn < _startColumn) {
_endColumn = start.columnIndex;
_startColumn = end!.columnIndex;
}
}
List<List<Data?>?> _selectedRange = <List<Data?>?>[];
if (_sheetData.isEmpty) {
return _selectedRange;
}
for (var i = _startRow; i <= (_endRow ?? maxRows); i++) {
var mapData = _sheetData[i];
if (mapData != null) {
List<Data?> row = <Data?>[];
for (var j = _startColumn; j <= (_endColumn ?? maxCols); j++) {
row.add(mapData[j]);
}
_selectedRange.add(row);
} else {
_selectedRange.add(null);
}
}
return _selectedRange;
}