是否可以使用任何 HTML5 功能将本地存储导出到 Excel?
这个问题类似,但没有强调任何导出的可能性 /em> 数据。想法?
This question is similar, but doesn't highlight any possibilities to export the data. Thoughts?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为您误解了所链接问题的答案,它建议您使用数据 URI 进行导出。
Excel 是一个有点复杂的目标,因为文件格式本身就是二进制的 (或 OOXML)。如果您只想在 Excel 中打开某些内容,那么您可以将更简单的 CSV 导出为数据 URI。以下代码有点粗糙,仅在 Firefox 中进行了测试:
这是页面标记:
此处演示。单击该按钮您将获得一个链接,单击该链接您将获得一个文件。更改值,再次单击链接,您将获得不同的文件。 Firefox 每次都让我选择 Excel 打开它,但我不知道这是我的配置问题还是一般问题。
(来源:boogdesign.com)
就像我说的,仅在 Firefox 中进行了测试,并且它仅适用于支持 数据 URI。您还需要 window.btoa() 函数或实现您自己的 base64 编码器。
I think you're misunderstanding the answer to the question you linked to, it's suggesting you use a Data URI for export.
Excel is a bit of a complicated target to aim for as the file format is itself binary (or OOXML). If you just want something that opens in Excel then you can export the more straightforward CSV as a data URI. The following code is a bit rough and ready and has only been tested in Firefox:
Here's the page markup:
Demo here. Click the button you get a link, click the link and you get a file. Change the values, click the link again and you get a different file. Firefox made me select Excel every time to open it but I don't know whether that's my configuration or a general issue.
(source: boogdesign.com)
Like I said, only tested in Firefox, and it will only work in browsers which support Data URIs. You also need the window.btoa() function or implement your own base64 encoder.
我不知道有任何 Javascript 库可以生成 Excel 文件。但您可以简单地将其导出为 HTML 或 CSV - 请注意,Javascript 还不能创建文件,但 HTML 的工作草案可以满足此要求:http://www.w3.org/TR/file-writer-api/
Excel 非常擅长读取 HTML 制作的表格,因此您可以简单地执行以下操作并使用 Excel 打开 HTML 文件。
您可以使用 Downloadify 创建一个供下载的文件: https://github.com/dcneiner/Downloadify
I'm not aware of any Javascript libraries which can make an Excel file. But you could simply export it as HTML or CSV - note that Javascript cannot make files (yet), but the working draft of HTML caters for this: http://www.w3.org/TR/file-writer-api/
Excel is quite good at reading tables made in HTML, so you could simply do that and open the HTML file with Excel.
You can create a file for download using Downloadify: https://github.com/dcneiner/Downloadify