private void
ExportGridToword()
{
DataTable dt = ViewState["dtt"]
as DataTable;
GridView gv = new GridView();
gv.HeaderStyle.BackColor = System.Drawing.Color.Red;//
System.Drawing.ColorTranslator.FromHtml("#DDDDDD");
gv.HeaderStyle.ForeColor = System.Drawing.Color.LightGray;//
System.Drawing.ColorTranslator.FromHtml("#CCCCCC");
gv.RowStyle.BackColor = System.Drawing.Color.LightCyan;//
System.Drawing.ColorTranslator.FromHtml("#454545");
gv.AlternatingRowStyle.BackColor = System.Drawing.Color.White;//
System.Drawing.ColorTranslator.FromHtml("#545454");
gv.DataSource = dt;
gv.DataBind();
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition",
"attachment;filename=krishraja.pdf");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
StringWriter sw = new
StringWriter();
HtmlTextWriter hw = new
HtmlTextWriter(sw);
gv.RenderControl(hw);
StringReader sr = new
StringReader(sw.ToString());
Document pdfDoc = new
Document(PageSize.A2,
10f, 10f, 10f, 0f);
HTMLWorker htmlparser = new
HTMLWorker(pdfDoc);
PdfWriter.GetInstance(pdfDoc,
Response.OutputStream);
pdfDoc.Header = new HeaderFooter(new Phrase("Header
Text"), false);
pdfDoc.Open();
htmlparser.Parse(sr);
pdfDoc.Close();
Response.Write(pdfDoc);
Response.End();
}
No comments:
Post a Comment