Generate office open XML excel file from javascript

落花浮王杯 提交于 2019-11-29 13:22:25

问题


Is there a way to generate an .xslx file from javascript and allow the user to download it by javascript? This page is geared towards being run offline in html 5 with no internet connectivity.


回答1:


You could generate a data URI, and let the user save the link. However, IE8 has very limited support for data URIs. There is a 32 KB limit, and it's not allowed to be used with a href.

Also, you still need to find a actual XLSX JS library... But it is possible.




回答2:


It has been done successfully by Ed Spencer. This project is using an EXT DataGrid as the source of the data, but I'm sure you could adapt it pretty easily.




回答3:


As Javascript has no file I/O, it's not going to be easy for your users to download. However, this kind of work is perfectly suited for a simple PHP script, which could generate your XSLX and save to your server dynamically.




回答4:


You can generate any Office document with OpenXML SDK for Javascript http://openxmlsdkjs.codeplex.com/

As for allowing the user to save a file from JS I recommend FileSaver.js https://github.com/eligrey/FileSaver.js/



来源:https://stackoverflow.com/questions/2742422/generate-office-open-xml-excel-file-from-javascript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!