如何以pdf格式导出datagridview数据 [英] How to export datagridview data in pdf

查看:83
本文介绍了如何以pdf格式导出datagridview数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello Guys,我想知道

Hello Guys,I want to know

How to export datagridview data in pdf i was googling but i can't found yet so please guys if you know about it please give me the solution with your code please don't put any link of any articles.

What I have tried:

public void ExportToPdf(DataTable dt)
               {
                   Document document = new Document();
                   PdfWriter writer = PdfWriter.GetInstance(document, new FileStream("c://sample.pdf", FileMode.Create));
                   document.Open();
                   iTextSharp.text.Font font5 = iTextSharp.text.FontFactory.GetFont(FontFactory.HELVETICA, 5);

                   PdfPTable table = new PdfPTable(dt.Columns.Count);
                   PdfPRow row = null;
                   float[] widths = new float[] { 4f, 4f, 4f, 4f };

                   table.SetWidths(widths);

                   table.WidthPercentage = 100;
                   int iCol = 0;
                   string colname = "";
                   PdfPCell cell = new PdfPCell(new Phrase("Products"));

                   cell.Colspan = dt.Columns.Count;

                   foreach (DataColumn c in dt.Columns)
                   {

                       table.AddCell(new Phrase(c.ColumnName, font5));
                   }

                   foreach (DataRow r in dt.Rows)
                   {
                       if (dt.Rows.Count > 0)
                       {
                           table.AddCell(new Phrase(r[0].ToString(), font5));
                           table.AddCell(new Phrase(r[1].ToString(), font5));
                           table.AddCell(new Phrase(r[2].ToString(), font5));
                           table.AddCell(new Phrase(r[3].ToString(), font5));
                       }
                   } document.Add(table);
                   document.Close();
               }

推荐答案

您没有说明您的代码存在问题...只是您希望有人这样做为你工作。这不是一个尚未解决的问题,许多人曾经这样做过。只需使用谷歌。



这将返回11,700结果



将数据表导出为pdf itextsharp [ ^ ]



c# - 将数据表转换为PDF - 堆栈溢出 [ ^ ]



c# - 我们如何使用iTextSharp将数据表导出为PDF? - 堆栈溢出 [ ^ ]



http://www.codeproject.com/Questions/647786/How-can-we-export-datatable-to-PDF-using-iTextShar [ ^ ]



如何使用iTextSharp将数据表导出为PDF ASP.NET | C#| MVC | EF |云| SQL Server | IIS |教程 [ ^ ]



现在,如果你想提供一个明确的解释,你正在尝试做什么以及为什么代码你提供的不起作用可能是第一步。直到那时,使用谷歌和我提供的链接来完成你想要的东西。
You haven't stated an issue with your code...only that you want someone to do the work for you. This isn't an issue that has gone unsolved, many people have done this at one time or another. Simply use google.

This returns 11,700 results

Export datatable to pdf itextsharp[^]

c# - Convert Datatable to PDF - Stack Overflow[^]

c# - How can we export datatable to PDF using iTextSharp? - Stack Overflow[^]

http://www.codeproject.com/Questions/647786/How-can-we-export-datatable-to-PDF-using-iTextShar[^]

How can we export datatable to PDF using iTextSharp | ASP.NET | C# | MVC | EF | Cloud | SQL Server | IIS | Tutorials[^]

Now if you'd like to provide a clear explanation of what it is you are trying to do and why the code you've provided isn't working that may be the first step. Till then, use google and the links i've provided to accomplish what it is you want.


参考这个链接将Gridview转换为PDF


这篇关于如何以pdf格式导出datagridview数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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