在C#中打印,另存为PDF和Excel [英] Print, Save as PDF and Excel in C#

查看:517
本文介绍了在C#中打印,另存为PDF和Excel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在C#中的gridview中有数据。我需要打印并另存为PDF和Excel。有没有最好的链接来完成所有操作。请有人帮助我.....

解决方案

请参阅以下链接。



导出为PDF



导出为PDF / Exel


我创建一个简单的RDLC (本地报告)网格绑定到数据集(与您的GridView相同)

然后您可以将其导出为PDF& Excel通过代码 http://forums.asp .net / t / 1556522.aspx?RDLC +导出+直接+到+ Excel +或+ + + +来自+代码隐藏 [ ^ ]你可以按照描述打印在其他地方或者您可以使用PDFSharp将一些javascript打印功能嵌入到导出的PDF文件中( http://stackoverflow.com/a/17732531 [ ^ ])在文件打开时直接打印。


要创建PDF,您可以使用iText的.NET端口;这个端口叫做iTextSharp:

http://en.wikipedia.org/wiki/IText [ ^ ],

http://itextpdf.com/ [ ^ ],

http://sourceforge.net/projects/itextsharp/ [ ^ ]。



我也提供了到iText的链接,因为几乎所有使用iTextSharp的文档都在那里,以Java文档的形式提供。



要导出作为Excel文档,您可以使用Open XML SDK:

http ://www.microsoft.com/en-us/download/details.aspx?id = 30425 [ ^ ]。



这样,就可以了支持新的基于XML的Office格式(如.DOCX,.XLSX),ECMA-376标准:

http://en.wikipedia.org/wiki/Microsoft_Office_XML_formats [ ^ ],

http://en.wikipedia.org/wiki/Office_Open_XML [ ^ ]。



这样,您可以在没有安装Office的情况下工作。此外,第三方软件支持这些文档。请查看我过去的答案:

将Office文档转换为PDF而不互操作 [ ^ ],
需要一个相当独特的WPF文本编辑器控件 [ ^ ],

您好如何使用c#.net 在Windows应用程序中显示word文件[ ^ ],

阅读没有使用Interop.word dll的word文件...不想在IIS中安装单词。 [ ^ ]。



这是另一种选择: http://npoi.codeplex.com/ [ ^ ]。



另请参阅此CodeProject文章:使用Open XML创建基本的Excel工作簿 [ ^ ]。



-SA

I've data in gridview in C#. I need to print and Save as PDF and Excel. Is there any best links to do this all operations. Someone help me please .....

解决方案

Refer following links.

Export to PDF

Export to PDF/Exel


I'd create a simple RDLC (local report) with a grid bound to a data set (the same you used for your GridView)
Then you can export it to PDF & Excel through code http://forums.asp.net/t/1556522.aspx?RDLC+Export+directly+to+Excel+or+PDF+from+codebehind[^] and you can get it printed as described here or you could embed some javascript print function into the exported PDF file using PDFSharp (http://stackoverflow.com/a/17732531[^]) to get it printed directly when the file is opened.


To create PDF, you can use the .NET port of iText; this port is called iTextSharp:
http://en.wikipedia.org/wiki/IText[^],
http://itextpdf.com/[^],
http://sourceforge.net/projects/itextsharp/[^].

I provided links to iText, too, because nearly all documentation you need to work with iTextSharp is there, provided as Java documentation.

To export as Excel document, you can use Open XML SDK:
http://www.microsoft.com/en-us/download/details.aspx?id=30425[^].

This way, you can support new XML-based Office formats (such as .DOCX, .XLSX), ECMA-376 standard:
http://en.wikipedia.org/wiki/Microsoft_Office_XML_formats[^],
http://en.wikipedia.org/wiki/Office_Open_XML[^].

This way, you can work without Office installed. Also, the documents are supported by 3rd-party software. Please see my past answers:
Convert Office-Documents to PDF without interop[^],
Need a rather unique WPF text editor control[^],
Hi how can i display word file in windows application using c#.net[^],
Read a word file without using Interop.word dll...Do not want to install word in IIS..[^].

This is another option: http://npoi.codeplex.com/[^].

See also this CodeProject article: Creating basic Excel workbook with Open XML[^].

—SA


这篇关于在C#中打印,另存为PDF和Excel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆