getLastRow method

int getLastRow()

get the index of the last row in UsedRange.

// Create a new Excel Document.
final Workbook workbook = Workbook(1);
// Accessing sheet via index.
final Worksheet sheet = workbook.worksheets[0];
final Range range = sheet.getRangeByName('A1:D4');
range.setText('Hi');

// get first row.
print(sheet.getFirstRow());
// get last row.
print(sheet.getLastRow());
// get first column.
print(sheet.getFirstColumn());
// get last Column.
print(sheet.getLastColumn());

// Save and dispose workbook.
final List<int> bytes = workbook.saveAsStream();
File('Output.xlsx').writeAsBytes(bytes);
workbook.dispose();

Implementation

int getLastRow() {
  int lastRow = -1;
  for (final Row? row in rows.innerList) {
    if (row != null && lastRow < row.index) {
      lastRow = row.index;
    }
  }
  return lastRow;
}