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!"); }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)