日期:2014-05-18 浏览次数:20419 次
/// <summary> /// 导出文件 /// </summary> /// <param name="ExportType">导出类型</param> /// <param name="FileName">导出文件名</param> /// <remarks>导出类型可以为application/ms-excel、application/ms-word、application/ms-txt、application/ms-html 或其他浏览器可直接支持文档</remarks> private void Export(DataGrid grid,string ExportType, string FileName) { Response.Clear(); Response.Buffer = true; Response.Charset = "GB2312"; Response.AppendHeader("Content-Disposition", "attachment;filename=" + FileName); Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312"); Response.ContentType = ExportType; System.IO.StringWriter stringWriter = new System.IO.StringWriter(); System.Web.UI.HtmlTextWriter htmlWriter = new System.Web.UI.HtmlTextWriter(stringWriter); grid.RenderControl(htmlWriter); Response.Write(stringWriter.ToString()); Response.End(); }