How I can export a datatable to excel 2007 and pdf from asp.net?

て烟熏妆下的殇ゞ 提交于 2020-01-06 05:35:13

问题


I have to make reports with graphics in Excel and PDF from data in a database in an asp.net app. I don't want to use com objects so I have been using Open Xml Sdk to build the excel file from a template file and redirect the response to the new file generated but I don't know how to make the PDF file... I accept any comments about how I can generate the pdf file in my web app... Thanks by the time invested reading this...


回答1:


go to this site for pdf.

http://itextsharp.sourceforge.net/




回答2:


I've done this before but with a bit of a cheat.

Office XP and onwards can actually read html files as office documents so if you sent a html document containing a table with the extension and mime type of an excel doc then windows would open it in excel.

From there you can use a web service such as http://www.htm2pdf.co.uk/htm2pdf-web-service.aspx to convert the html table data into a pdf.

Even better than that if you change the extension of a docx or xslx file to zip you can unzip the stored files and you'll find they are xml files that you can edit and rezip (changing the extension back of course).




回答3:


The easiest solution -- in my opinion -- is to use Client Report Definition Files. After you defined reports, you can

  • show them to users in your ASP.NET application using the ReportViewer component (Google for asp.net ReportViewer),
  • export them directly to Excel (Google for localreport excel),
  • export them directly to PDF (Google for localreport pdf).

For the last two options, you can either save the file to disk or send it directly to the asp.net client (again, there are lots of code examples on the web).



来源:https://stackoverflow.com/questions/1669613/how-i-can-export-a-datatable-to-excel-2007-and-pdf-from-asp-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!