Closed algi-cap closed 3 years ago
When exporting into xlsx format, the xlsx file should never be base64 encoded. The only reason this can happen is an exception while saving the file. You should have a look to the js console if there are any errors while the file is generated. If an exception occurs at this point, most likely something is wrong with the FileSaver library. BTW: An XLSX file is actually a zip archive that can be opened with an appropriate archive program.
Thanks for reply, @hhurz . The js console did not show errors but I found a different behavior when using FileSaver.js or the minified version FileSaver.min.js. This is what happens with FileSaver.js:
This is what happens with FileSaver.min.js instead:
Said this, the minified FileSaver.min.js has some code difference that allows to download the XLSX file without network error but, unfortunately, if I open the file with notepad++ I still see base64 encoded data:
So the downloaded file is not a valid XLSX (also trying to change the extension from ".xlsx" to ".zip" I cannot open the zip archive due to "invalid archive").
But I don't know how to fix this, because it seems that the only feasible way to download a file created from JS client code is via base64 encoding. What do you suggest?
stepping into "saveAs" function I see that the URL.createObjectUrl function is being called (and here the base64 encoding takes place)
Just for clarification: the URL.createObjectUrl function doesn't encode any thing. If the base64 encoding took place, then there occured an exception while URL.createObjectUrl was called. I cross checked the xlsx export of my test page with Chrome and Firefox without any issues. Also swapping from FileSave.min.js to the FileSaver.js did work as exspected. Here are a few suggestions, although i have to admit, I have no real idea what is going wrong on your site: Your are working with Chrome, right? Have you tried it within Firefox? Sometimes the include order of the js libs is important. I recommend to include FileSaver straight after jQuery and before all other libs.
I made some step ahead understanding what causes this behavior. Long story short: XLSX can't cohexist with jsPDF export. If I don't include jsPDF and jsPDF AutoTable plugin the XLSX is being exported correctly and I can open the file:
If you include jsPDF and jsPDF AutoTable the XLSX export is being compromised independently from where you place the two scripts (before or after XLSX js). Let me know if you can reproduce this and if you have some suggestion. Thanks.
Thanks for digging into this. Strange. Your include order above is exactly the same i am using in my test page. The only difference: is, that I don't use xlsx.full.min.js but xlsx.core.min.js. But also swaping these files, everything works fine, Thus I can't reproduce what you observed. Would you repeat your test using the libs I included here? Perhaps it's a version conflict.
I've double checked the libs I'm using and all but xlsx.full.min.js are libs downloaded from this repo (so the link you posted). So I replaced xlsx.full.min.js with xlsx.core.min.js downloaded from this repo but nothing has changed (same issue). This is the current script importing list:
Btw, I have some other script after the ones shown in the picture above. I don't post them because I already tried to remove them and the behavior doesn't change, so I think they aren't relevant for this scenario (they're all related to bootstrap-table, bootstrap-datepicker and some personal js code).
Thank you for investigating the issue further. I have now updated my bootstrap tests to the latest bootstrap and bootstrap table versions and included the JS files you mentioned as well. Still can't reproduce the issue you described! Please have a look at the example bnotstrap4: Both export to xlsx and export to PDF work as expected. The include order is the same as you described. There are no js console errors
I hate to say this, but something on your side must be causing the problem. Maybe you run the bootstrap4 sample file yourself and see if it works for you. As long as I don't have more details or insight into your implementation, I have no more ideas.
Hi, I'm facing the issue using last stable of tableExport (and dependencies). The code doesn't throw exceptions but when the file is being downloaded the browser returns "failed - network error". Please see the attached image:
I didn't write code by myself because I'm working on bootstrap-table with its "export" extension and that's based on tableExport plugin, so the underneath code is a blackbox to me. I also tried to debug non minified versions of tableExport, sheetjs and filesaver libs to check if there was some obvious problem without success.
Googling around day-night I found someone that says that the base64 encoded string could be malformed or contain some bad data.
This is an example of the anchor tag that is being created underneath:
Hope this helps someone to help me because I don't know what else to check! Thanks