开发者

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

开发者 https://www.devze.com 2022-12-10 07:47 出处:网络
I have to make reports w开发者_运维问答ith graphics in Excel and PDF from data in a database in an asp.net app.

I have to make reports w开发者_运维问答ith 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...


go to this site for pdf.

http://itextsharp.sourceforge.net/


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).


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).

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号