Problem to read the merged cells from excel(.xlsx) dependency in flutter

Viewed 69

According to documentation of Excel dependency in flutter, sheetObject.spandedItems returns a List of merged cells. My .xlsx file has several merged cells but sheetObject.spannedItems list show empty list.

_importExcelfile() function pick a file from local directory and read excel file.

Excel dependency link: here

Here is the code:

  void _importExcelFile() async {
    FilePickerResult? result = await FilePicker.platform.pickFiles();//pick a file
    if (result != null) {
      File file = File(result.files.single.path!);
    } else {
      // User canceled the picker
    }
    if (result != null) {
      PlatformFile file = result.files.first;

      if (file.extension == 'xlsx') {
        var _file = file.path; // path of local directory
        var bytes = File(_file!).readAsBytesSync();
        var excel = Excel.decodeBytes(bytes);

        for (var table in excel.tables.keys) {
          Sheet sheetObject = excel[table];
          var span = sheetObject.spannedItems; // list of spanned cells 
          print('Spanded Items :');
          print(span);

          print("length of spandedItems:" +
              sheetObject.spannedItems.length.toString());
        }
      } else {
        //print("Please insert excelfile");
      }
    }
  }
}

Output:

output

Image of Excel file : here

0 Answers
Related