Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FileSystemException: Cannot open file, path = 'assets/database.xlsx' (OS Error: No such file or directory, errno = 2) #12

Closed
Logophoman opened this issue May 13, 2020 · 4 comments

Comments

@Logophoman
Copy link

Hey all,

I'm trying to load an .xlsx file in order to convert its contents into a list.
I've tied to follow the documentation, yet without success, since the file is not recognized even tough (imo) everything is in place.
I've imported many images and other files and everything works well except that...

I've cleand my flutter and all dependencies work just fine.
The file is in place and not corrupt.
The file is referrenced in the assets section of my pubspec.yaml

My trouble code is (second line):
var file = 'assets/database.xlsx'; var bytes = File(file).readAsBytesSync();

Pubspec:
assets: - assets/database.xlsx

The full error message is:
E/flutter ( 9858): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: FileSystemException: Cannot open file, path = 'assets/database.xlsx' (OS Error: No such file or directory, errno = 2) E/flutter ( 9858): #0 _File.throwIfError (dart:io/file_impl.dart:645:7) E/flutter ( 9858): #1 _File.openSync (dart:io/file_impl.dart:489:5) E/flutter ( 9858): #2 _File.readAsBytesSync (dart:io/file_impl.dart:549:18) E/flutter ( 9858): #3 _MyHomePageState.readExcel (package:prophetix/main.dart:106:28) E/flutter ( 9858): #4 _MyHomePageState.searchDB (package:prophetix/main.dart:121:5) E/flutter ( 9858): <asynchronous suspension> E/flutter ( 9858): #5 SearchBarController._search (package:flappy_search_bar/flappy_search_bar.dart:50:17) E/flutter ( 9858): #6 _SearchBarState._onTextChanged.<anonymous closure> (package:flappy_search_bar/flappy_search_bar.dart:295:29) E/flutter ( 9858): #7 _rootRun (dart:async/zone.dart:1122:38) E/flutter ( 9858): #8 _CustomZone.run (dart:async/zone.dart:1023:19) E/flutter ( 9858): #9 _CustomZone.runGuarded (dart:async/zone.dart:925:7) E/flutter ( 9858): #10 _CustomZone.bindCallbackGuarded.<anonymous closure> (dart:async/zone.dart:965:23) E/flutter ( 9858): #11 _rootRun (dart:async/zone.dart:1126:13) E/flutter ( 9858): #12 _CustomZone.run (dart:async/zone.dart:1023:19) E/flutter ( 9858): #13 _CustomZone.bindCallback.<anonymous closure> (dart:async/zone.dart:949:23) E/flutter ( 9858): #14 Timer._createTimer.<anonymous closure> (dart:async-patch/timer_patch.dart:23:15) E/flutter ( 9858): #15 _Timer._runTimers (dart:isolate-patch/timer_impl.dart:384:19) E/flutter ( 9858): #16 _Timer._handleMessage (dart:isolate-patch/timer_impl.dart:418:5) E/flutter ( 9858): #17 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:174:12) E/flutter ( 9858):

Any help is very appreciated. Thank you for your time!

@justkawal
Copy link
Owner

justkawal commented May 13, 2020

Try this code:

import 'package:flutter/services.dart' show ByteData, rootBundle;

/* Your something important code */

ByteData data = await rootBundle.load("assets/database.xlsx");
var bytes = data.buffer.asUint8List(data.offsetInBytes, data.lengthInBytes);
var excel = Excel.decodeBytes(bytes, update: true);

Tell me if this works
~Thank You
LONG LIVE OPEN S🔥URCE

@Logophoman
Copy link
Author

Just works like a charm!!!

Awesome 😊!

You really made my day!

@justkawal
Copy link
Owner

Happy to Help.

@khallediRA
Copy link

khallediRA commented Nov 18, 2020

Hey @justkawal which version of the plugin should I use in this function ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants