Decoding does not work on client
Opened this issue · 5 comments
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
Did you try to load the file using server-side code ?
What is your context ? Dart version ? archive package version...
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?
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);
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
My advice was to test your file without using web client, in other words, try your file using command-line code.