如何使用第三方dll创建来自datatable或windows格式的datagridview的pdf,如itextsharp mor pdfsharp [英] how to create pdf from datatable, or datagridview in windows form using 3rd party dll like as itextsharp mor pdfsharp

查看:112
本文介绍了如何使用第三方dll创建来自datatable或windows格式的datagridview的pdf,如itextsharp mor pdfsharp的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的代码m使用datagridview

Here is my code m using datagridview

public void pdf()
{

    Document doc = new Document(iTextSharp.text.PageSize.LETTER, 10, 10, 42, 35);
    PdfWriter wri = PdfWriter.GetInstance(doc, new FileStream("d:\\Test.pdf", FileMode.Create));

    doc.Open();//Open Document to write


    Paragraph paragraph = new Paragraph("data Exported From DataGridview!");

    // Create table by setting table value

    Table t1 = new Table(2);
    DataTable dt = (DataTable)datagrigview.DataSource;

    // Create Table Header

    Cell cid = new Cell("Tank Name");
    Cell cname = new Cell("Frames");

    t1.AddCell(cid);
    t1.AddCell(cname);

    foreach (DataGridViewRow rows in dgv.Rows)
    {

        string id = dgv.Rows[rows.Index].Cells["Tank_Name"].Value.ToString();  //I Got Error here that Cells["Tank_Name"] is object refrance is not set as an instance of an object
        string name = dgv.Rows[rows.Index].Cells["Frames"].Value.ToString();
        //  Create Cells
        Cell c2 = new Cell(id);
        Cell c1 = new Cell(name);
        //  Adding cells
        t1.AddCell(c1);
        t1.AddCell(c2);

    }
    doc.Add(paragraph);
    doc.Add(t1);
    doc.Close(); //Close document

    MessageBox.Show("PDF Created!");

}

推荐答案

这篇关于如何使用第三方dll创建来自datatable或windows格式的datagridview的pdf,如itextsharp mor pdfsharp的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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