且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何将html表导出为xlsx文件

更新时间:2023-01-31 19:10:00

您将无法将其导出为XLSX而不返回到服务器。 XLSX文件是XML文件的集合,压缩在一起。这意味着你需要创建多个文件。这不可能与JS,客户端。

You won't be able to export it as XLSX without going back to the server. A XLSX file is a collection of XML files, zipped together. This means you do need to create multiple files. This is impossible to do with JS, client-side.

相反,您应该创建一个从HTML表中检索数据并将其发送给您的服务器的功能。然后,服务器可以为您创建XLSX文件(有一堆可用于此!),并将其发送回客户端进行下载。

Instead, you should create a function retrieving the data from your HTML table and send that to you server. The server can then create the XLSX file for you (there are a bunch of libs available for that!) and send it back to the client for download.

如果您期望要拥有一个巨大的数据集,服务器上的XLSX创建应该作为一个异步进程完成,在这个过程中,您通知用户完成(而不是让用户等待该文件被创建)。

If you expect to have a huge dataset, the XLSX creation on the server should be done as an async process, where you notify the user when it's done (instead of having the user waiting for the file to be created).

让我们知道您在服务器上使用哪种语言,我们可以向您推荐一些很好的图书馆。

Let us know which language you use on your server, and we'll be able to recommend you some good libraries.