Export Datagrid Data To MS-Word
private void btnExportToWord_Click(object sender,
System.EventArgs e)
{
ExportToWord("Report.doc",DataGrid1);
}
private void ExportToWord(string strFileName,DataGrid dg)
{
Response.Clear();
Response.Buffer = true;
Response.ContentType = "application/vnd.ms-word";
Response.AddHeader("content-disposition",
"attachment;filename=" + strFileName);
Response.Charset = "";
this.EnableViewState = false;
System.IO.StringWriter sw = new StringWriter();
System.Web.UI.HtmlTextWriter htw = new HtmlTextWriter(sw);
dg.RenderControl(htw);
Response.Write(sw.ToString());
Response.End();
}
No comments:
Post a Comment