Generate office open XML excel file from javascrip

2019-02-06 18:10发布

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.

4条回答
Root(大扎)
2楼-- · 2019-02-06 18:35

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/

查看更多
3楼-- · 2019-02-06 18:37

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楼-- · 2019-02-06 18:39

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.

查看更多
forever°为你锁心
5楼-- · 2019-02-06 18:41

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.

查看更多
登录 后发表回答