Reputation: 121
I am currently using the 'excel 1.1.5' package for Flutter to read the Excel file.
My data in the excel file is as under
I am using the following code to read the excel file
List<String> rowdetail = [];
_importFromExcel() async {
var file =
"storage/emulated/0/Android/data/com.xxxx.xxxx/files/Download/Input.xlsx";
var bytes = File(file).readAsBytesSync();
var excel = Excel.decodeBytes(bytes);
for (var table in excel.tables.keys) {
for (var row in excel.tables[table]!.rows) {
rowdetail.add(row.toString());
}
}
}
However, when I print the data, every column is wrapped with additional values which I do not want.
I/flutter (12873): [Data(1, 0, 0, null, Sheet1), Data(Assets, 1, 0, null, Sheet1), Data(Bank accounts, 2, 0, null, Sheet1), Data(Cb 7723, 3, 0, null, Sheet1), Data(2022-05-26 10:46:07.679579, 4, 0, null, Sheet1), Data(27, 5, 0, null, Sheet1), Data(6269, 6, 0, null, Sheet1), Data(, 7, 0, null, Sheet1)]
As can be noticed, the first row, first column is prefixed with "Data(" and suffixed with "0, 0, null, Sheet1)".
How to access only the required data in the file. (in this case, the first row, first column value should be only "1").
Upvotes: 0
Views: 12857
Reputation: 109
Just use row.value instead of row.toString()
This should work:
List<String> rowdetail = [];
_importFromExcel() async {
var file =
"storage/emulated/0/Android/data/com.xxxx.xxxx/files/Download/Input.xlsx";
var bytes = File(file).readAsBytesSync();
var excel = Excel.decodeBytes(bytes);
for (var table in excel.tables.keys) {
for (var row in excel.tables[table]!.rows) {
rowdetail.add(row.value);
}
}
}
Upvotes: 4