GridView导出EXCEL文本格式

private void ReportExportByGridView(GridView gridview)
        {
            Response.ClearContent();

            Response.AddHeader("content-disposition", "attachment; filename=MyExcelFile.xls");

            Response.ContentEncoding = System.Text.Encoding.UTF8;

            Response.ContentType = "application/excel";

            string strStyle = "<style>td{mso-number-format:\"\\@\";}</style>";

            StringWriter sw = new StringWriter();

            HtmlTextWriter htw = new HtmlTextWriter(sw);

            gridview.Page.EnableViewState = false;

            sw.WriteLine(strStyle);

            gridview.RenderControl(htw);

            Response.Write(sw.ToString());

            Response.End();

        }

你可能感兴趣的:(GridView导出EXCEL文本格式)