Error in reading excel in flutter using excel package

660 views Asked by At

Code:

filename = "xls_path/sample.xlsx";
final File file = File(filename);
List<int> bytes = file.readAsBytesSync(); (Getting below error in this line)
var excel = Excel.decodeBytes(bytes.toList());

Extract of package:excel/src/sheet/header_footer.dart:193:5

extension BoolParsing on String {
bool parseBool() 

 {
        if (this.toLowerCase() == 'true') {
        return true;
 } else if (this.toLowerCase() == 'false') {
       return false;
 }

    throw '"$this" can not be parsed to boolean.';

  }
}

Error: [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: "0" can not be parsed to boolean. E/flutter ( 5250): #0 BoolParsing.parseBool (package:excel/src/sheet/header_footer.dart:193:5) E/flutter ( 5250): #1 HeaderFooter.fromXmlElement (package:excel/src/sheet/header_footer.dart:169:67) E/flutter

( 5250): #2 Parser._parseHeaderFooter (package:excel/src/parser/parse.dart:696:45) E/flutter ( 5250): #3 Parser._parseTable (package:excel/src/parser/parse.dart:439:5) E/flutter ( 5250): #4 Parser._parseContent.<anonymous closure> (package:excel/src/parser/parse.dart:160:9) E/flutter ( 5250): #5 Iterable.forEach (dart:core/iterable.dart:325:35) E/flutter ( 5250): #6 Parser._parseContent (package:excel/src/parser/parse.dart:158:39) E/flutter ( 5250): #7 Parser.startParsing (package:excel/src/parser/parse.dart:18:5) E/flutter ( 5250): #8 new Excel. (package:excel/src/excel.dart:74:12) E/flutter ( 5250): #9 _newExcel (package:excel/src/excel.dart:17:20)

I have tried reading already existing excel workbook and append new rows to the sheet and save it. Package used excel: ^2.0.1, excel: ^2.0.0-null-safety-3.

I expect to read and save with new data using flutter excel package.

1

There are 1 answers

2
bakboem On
  • Use the path_provider plugin to get the storage path of ios/android

  • like this

  Future<Directory?> getLocalDirectory() async {
    return Platform.isAndroid
        ? await path.getExternalStorageDirectory()
        : await path.getApplicationSupportDirectory();
  }