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

Decoding does not work on client #25

Open
kevag opened this issue Apr 21, 2020 · 5 comments
Open

Decoding does not work on client #25

kevag opened this issue Apr 21, 2020 · 5 comments
Labels

Comments

@kevag
Copy link

kevag commented Apr 21, 2020

Hello,

I am trying to parse an xlsx file on client right after selecting it on an input. I am following the steps suggested in readme file but it seems that the file is not loaded correctly into the archive.

My code:
void onFileUpload(Event event) { final List<File> files = (event.target as InputElement).files; final File file = files[0]; final FileReader reader = FileReader(); reader.onLoad.listen((_) { var decoder = SpreadsheetDecoder.decodeBytes(reader.result); var table = decoder.tables['Sheet1']; var values = table.rows[0]; print(values); }); reader.readAsArrayBuffer(file); }

Note that the above code works for images, so i am pretty sure that this part is OK. The exception that I get:
EXCEPTION: NoSuchMethodError: invalid member on null: 'decompress' STACKTRACE: package:spreadsheet_decoder/src/xlsx.dart 285:9 [_parseTable] package:spreadsheet_decoder/src/xlsx.dart 274:7 <fn> dart:sdk_internal 14797:11 forEach package:spreadsheet_decoder/src/xlsx.dart 273:30 [_parseContent] package:spreadsheet_decoder/src/xlsx.dart 110:5 new package:spreadsheet_decoder/src/spreadsheet.dart 38:14 _newSpreadsheetDecoder package:spreadsheet_decoder/src/spreadsheet.dart 76:12 decodeBytes

So, the problem is in xlsx.dart file, inside _parse table line 285, var file = _archive.findFile("xl/$target"); does not find the file in the archive and returns null.

BRs / Kostas

@sestegra sestegra added the usage label Apr 21, 2020
@sestegra
Copy link
Owner

Did you try to load the file using server-side code ?
What is your context ? Dart version ? archive package version...

@kevag
Copy link
Author

kevag commented Apr 21, 2020

Unfortunately, I use the web sdk. I cannot use server side code as I am not able to load dart.io lib on web.

My dart version is 2.8.0.
I am not using archive package so I guess it is the version that you import in your package.

But have you tested it yourself on client side? Was that working in first place?

@sestegra
Copy link
Owner

The code is automatically tested with unitary test on server and on client (see test folder).

To test on "server-side" code, you just have to create Dart program on your project.
For instance, create bin/debug.dart with following lines in your main function:

var bytes = File.fromUri("document.xlsx").readAsBytesSync();
var decoder = SpreadsheetDecoder.decodeBytes(bytes);

@kevag
Copy link
Author

kevag commented Apr 21, 2020

But the File.fromUri("document.xlsx").readAsBytesSync(); line requires the import of dart:io package which is NOT allowed on web dart. So you see my problem?
Also, on web sdk, when I am inserting the xlsx from an input element, the browser hides the full uri.

Nevertheless, I need to be able to parse it using the Filereader from dart:html as in my code above but it seems that this fault not inserting the file correctly inside archive.
I cannot say why this is happening as the bytes variable seems to be correct from the Filereader:
reader.readAsArrayBuffer(file);

I would be grateful if you can take a look and fix this one.

BRs / Kostas

@sestegra
Copy link
Owner

My advice was to test your file without using web client, in other words, try your file using command-line code.

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

No branches or pull requests

2 participants