简体   繁体   English

使用 Javascript(客户端)生成 PDF 和 Excel

[英]Generate PDF and Excel using Javascript (Client side)

Is there a client side Javascript framework similar to jasper report in Java.My requirement is to generate both PDF and Excel at client side(browser) without doing it at server side.是否有类似于 Java 中的 jasper 报告的客户端 Javascript 框架。我的要求是在客户端(浏览器)生成 PDF 和 Excel,而不是在服务器端生成。 I have found that there are javascript libraries like JsPDF and PDFkit to generate PDF and different library for generate Excel which make the development effort much harder.I want some thing exactly similar to what is done by jasper report.Also if it can be added using NPM without manual importing to the code and use it then it is much suitable for my requirement.我发现有像 JsPDF 和 PDFkit 这样的 javascript 库来生成 PDF 和不同的库来生成 Excel,这使得开发工作变得更加困难。我想要一些与 jasper report 所做的完全相似的事情。如果它可以添加使用NPM 无需手动导入代码并使用它,它非常适合我的要求。

i believe jquery datatable comes with all you need check it out https://datatables.net/extensions/buttons/examples/initialisation/export.html我相信 jquery 数据表附带了所有你需要的东西,看看https://datatables.net/extensions/buttons/examples/initialisation/export.html

I am afraid you have to use two separate libraries that best fit your needs, one for PDF and another for Excel.恐怕您必须使用两个最适合您需要的独立库,一个用于 PDF,另一个用于 Excel。 If you think about it, it makes sense.如果你考虑一下,这是有道理的。

It is a huge undertaking to render PDFs with plain Javascript, just look at the complexity of PDF.js alone.用纯 Javascript 渲染 PDF 是一项艰巨的任务,仅看PDF.js的复杂性。 Excel is no different. Excel 也不例外。 These are complex formats.这些是复杂的格式。

Your use case is to render PDF and Excel.您的用例是呈现 PDF 和 Excel。 Somebody else might want to render PDF and DOC.其他人可能想要呈现 PDF 和 DOC。 You get the idea, there are tons of different formats out there, and there is no single library to handle them all.你明白了,那里有大量不同的格式,并且没有一个库可以处理所有这些。 Even if someone had enough resources to build something like that, it would probably be broken up into modules that you can pick and choose based on your needs.即使有人有足够的资源来构建这样的东西,它也可能会被分解成模块,您可以根据需要进行选择。 A single framework would be too big to be practical for the web.一个单一的框架对于 web 来说太大了而不实用。

Thanx Fadi and Axel for your prompt response.Yes the solution you have mentioned is a good one which is not known by me.There is a limitation in that solution when it is going to be used for my requirement.Refer the following screen shot of the report that I have to generate as PDF and Excel using javascript library.In that report it is not only the data table which need to be included to the document.But also some detail on the top and a logo.Also the application is developed using EmberJS and this jquery table plugin cant be used since we are using the Ember table which cant be replaced by this Jquery table.Is there an alternative solutions except Jquery data table?感谢 Fadi 和 Axel 的及时回复。是的,你提到的解决方案是一个很好的解决方案,但我不知道。该解决方案在用于我的要求时存在局限性。请参阅以下屏幕截图我必须使用 javascript 库生成 PDF 和 Excel 格式的报告。在该报告中,不仅需要将数据表包含在文档中。而且顶部还有一些细节和徽标。还开发了应用程序使用 EmberJS 和这个 jquery 表插件不能使用,因为我们使用的是不能被这个 Jquery 表替换的 Ember 表。是否有除了 Jquery 数据表之外的替代解决方案?

在此处输入图像描述

https://jsreport.net , for those still looking, check this out! https://jsreport.net ,对于那些仍在寻找的人,请检查一下!

Credits: jsreport Author致谢: jsreport 作者

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM