在asp.net中导出为PDF

时间:2014-07-03 06:44:40

标签: c# asp.net pdf

以下代码用于将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();

0 个答案:

没有答案