justkawal / excel

Excel Library for Flutter and Dart - https://pub.dev/packages/excel
MIT License
427 stars 239 forks source link

Cannot open file on Mac OS #326

Open ben55j opened 9 months ago

ben55j commented 9 months ago

Hello,

I am trying this package on MacOs for reading at an .xlsx file located in "./test/example.xlsx" (same level as the lib folder).

Here is my code for getting the file.

testExcel(int` counter) async {

  var file = './test/example.xlsx';
  var bytes = File(file).readAsBytesSync();
  var excel = Excel.decodeBytes(bytes);
  //....
  }

But, for some reason, the app cannot access to it ..and I dont understand why.

Here is the error I get:

[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: PathNotFoundException: Cannot open file, path = './test/example.xlsx' (OS Error: No such file or directory, errno = 2)
#0      _File.throwIfError (dart:io/file_impl.dart:675:7)
#1      _File.openSync (dart:io/file_impl.dart:490:5)
#2      _File.readAsBytesSync (dart:io/file_impl.dart:574:18)
#3      testExcel (package:us_manager/main.dart:90:26)
#4      _MyHomePageState._incrementCounter (package:us_manager/main.dart:42:5)
#5      _InkResponseState.handleTap (package:flutter/src/material/ink_well.dart:1183:21)
#6      GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:275:24)
#7      TapGestureRecognizer.handleTapUp (package:flutter/src/gestures/tap.dart:652:11)
#8      BaseTapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:309:5)
#9      BaseTapGestureRecognizer.handlePrimaryPointer (package:flutter/src/gestures/tap.dart:242:7)

Can you help? Many Thanks Benjamin

rf43 commented 3 months ago

This has less to do with the library and more to do with your path and File.

Are you sure your file is actually located at that path because the error is saying that there is no file with that name in that path.