任何人都可以使用生成pdf或Excel的HTML / Javascript提供代码吗? [英] Can anyone provide a code using HTML/Javascript which generate a pdf or excel ?
问题描述
我有一个html文件。
首先,我需要使用JavaScript创建一个保存按钮。
当我按下保存按钮时,它会将div的内容保存为excel或pdf。
任何人都可以为此提供代码目的?
对于Excel
参考 - 如何通过Javascript生成Excel [ ^ ]。
引用:你可以生成你喜欢的任何东西,但问题是 - 如何你打算把它呈现给用户吗?如果您的JS在浏览器中运行,您将无法创建另存为对话框,甚至无法在同一窗口中打开它。除非您使用某些ActiveX控件,但这是一个仅限IE的解决方案,它还会在用户开始工作之前给出一些确认提示。
您也可以尝试 Excel Builder(.js) [ ^ ]。
PDF格式
参考 - 使用Javascript生成PDF文件 [ ^ ] 。
引用:我刚写了一个名为的库 jsPDF ,仅使用Javascript生成PDF。它还很年轻,我很快就会添加功能和错误修复。还有一些关于不支持数据URI的浏览器的变通方法的想法。它是在自由MIT许可下获得许可的。
在我开始写这篇文章之前,我遇到过这个问题并且认为我会回来让你知道:)
I have a html file.
Firstly, i need to create a save button using JavaScript.
When i will press save button it will save the content of div into an excel or pdf.
Can anyone provide the code for this purpose?
For Excel
Refer - how to generate Excel through Javascript[^].
Quote:You can generate whatever you like, but the question is - how are you going to present it to the user? If your JS runs in the browser, you won't be able to make a save-as dialog box or even open it in the same window. Not unless you use some ActiveX controls, but that's an IE-only solution which will also give the user a few confirmation prompts before it starts to work.
You can also try Excel Builder(.js)[^].
For PDF
Refer - Generating PDF files with Javascript[^].
Quote:I've just written a library called jsPDF which generates PDFs using Javascript alone. It's still very young, and I'll be adding features and bug fixes soon. Also got a few ideas for workarounds in browsers that do not support Data URIs. It's licensed under a liberal MIT license.
I came across this question before I started writing it and thought I'd come back and let you know :)
这篇关于任何人都可以使用生成pdf或Excel的HTML / Javascript提供代码吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!