getRangeByIndex method

Range getRangeByIndex(
  1. int rowIndex,
  2. int columnIndex, [
  3. int lastRowIndex = -1,
  4. int lastColumnIndex = -1,
])

Get range by index value.

Workbook workbook = new Workbook();
Worksheet sheet = workbook.worksheets[0];
sheet.getRangeByIndex(1, 1, 2, 2);
List<int> bytes = workbook.saveAsStream();
File('Range.xlsx').writeAsBytes(bytes);
workbook.dispose();

Implementation

Range getRangeByIndex(int rowIndex, int columnIndex,
    [int lastRowIndex = -1, int lastColumnIndex = -1]) {
  checkRange(rowIndex, columnIndex);
  if (lastRowIndex != -1 && lastColumnIndex != -1) {
    checkRange(lastRowIndex, lastColumnIndex);
  }

  Range? range;
  if ((rowIndex == lastRowIndex && columnIndex == lastColumnIndex) ||
      (lastRowIndex == -1 && lastColumnIndex == -1)) {
    range = _getRangeFromSheet(rowIndex, columnIndex);
    if (range == null) {
      range = Range(this);
      range.row = rowIndex;
      range.column = range.index = columnIndex;
    }
    range.lastRow = rowIndex;
    range.lastColumn = columnIndex;
  } else {
    range = Range(this);
    range.row = rowIndex;
    range.column = range.index = columnIndex;
    range.lastRow = lastRowIndex;
    range.lastColumn = lastColumnIndex;
  }
  return range;
}