streamRowsAsMaps method
Reads sheetName row by row as maps keyed by a header row.
The same lazy, memory-bounded walk as streamRows, with each row turned
into a Map<String, dynamic> using the names in headerRow (row 0 by
default). Header naming matches Sheet.rowsAsMaps: an empty header cell
falls back to its column letter and a repeated name gets a _2 suffix,
so no column is dropped.
Values are each cell's .value, or null for an empty cell.
for (final row in excel.streamRowsAsMaps('Sheet1')) {
print(row['email']);
}
Implementation
Iterable<Map<String, dynamic>> streamRowsAsMaps(
String sheetName, {
int headerRow = 0,
}) sync* {
if (headerRow < 0) {
throw ArgumentError.value(headerRow, 'headerRow', 'must not be negative');
}
List<String>? headers;
var index = 0;
for (final row in streamRows(sheetName)) {
if (index < headerRow) {
index++;
continue;
}
if (headers == null) {
headers = _jsonHeaderKeys(row);
index++;
continue;
}
final map = <String, dynamic>{};
for (var i = 0; i < headers.length; i++) {
final cell = i < row.length ? row[i] : null;
map[headers[i]] = _scalarFromCell(cell, formulasAsText: false);
}
yield map;
index++;
}
}