How can I pass an Excel created with XML to PDF MVC

a 夏天 提交于 2019-12-11 20:26:53

问题


I need to create a PDF from an Excel created with XML. My application is based on MVC 4.0. Searching I found ITextSharp but I can't find examples of code or something like that.

How can I export to PDF from Excel using ITextSharp?


回答1:


First, separate the program from the file format and the API. Excel is a desktop spreadsheet program. XLS and XLSX are binary file formats for storing spreadsheet information. Open XML is a broad subject but usually refers to either the zipped XML file format Microsoft created for recent versions of Office or the .Net APIs for interacting with those files.

If you want to save an Excel document to a PDF file then you need to automate Excel.

If you want to convert an XLS/XLSX file to PDF then you'll need a translation layer and iTextSharp has zero knowledge of the XLS or XLSX file formats. The XLS spec is 1,185 pages, the XLSX spec is 299 pages plus references for generic Open XML concepts and the PDF 1.7 spec (and you should probably get ISO 32000 instead) is 1,310 pages so I'd recommend exploring 3rd part libraries for this instead (and I don't have a recommendation for any either).

If you are programmatically walking structured data in C#, however, I'd recommend just creating your PDF at the same time as your XLSX file. iTextSharp has a very, very nice table API that can auto-format column widths and heights so you don't have to worry about that (unless you want to). You seriously should be able to create a PDF with iTextSharp with the same or probably even less code than your XLSX code. A quick search for iTextSharp table should give you many options. If your structured data is a GridView or something similar you could even use ASP.Net to create HTML for you and have iTextSharp parse that into PDF commands.



来源:https://stackoverflow.com/questions/27822343/how-can-i-pass-an-excel-created-with-xml-to-pdf-mvc

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