以下代码用于将grid data
导出到PDF
。此代码适用于除.docx
之外的.xls
和.pdf
个扩展程序!它实际上无法找到文件的内容类型!
你能帮我找到解决方案吗?
CODE:
System.Web.UI.WebControls.DataGrid grid =
new System.Web.UI.WebControls.DataGrid();
grid.HeaderStyle.Font.Bold = true;
grid.DataSource = ds;
grid.DataBind();Response.Clear();
Response.Buffer = true;
Response.ClearContent();
Response.ClearHeaders();
Response.Charset = "";
StringWriter strwritter = new StringWriter();
HtmlTextWriter htmltextwrtter = new HtmlTextWriter(strwritter);
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.ContentType = "application/pdf";
Response.AddHeader("Content-Disposition", "inline;filename=abc.pdf");
grid.GridLines = GridLines.Both;
grid.HeaderStyle.Font.Bold = true;
grid.RenderControl(htmltextwrtter);
Response.Write(strwritter.ToString());
Response.End();