本帖最后由 宋兴征 于 2013-5-14 14:49 编辑
用的这段导出到Excel的代码:- /// <summary>
- /// 将结果集导出到Excel
- /// </summary>
- /// <param name="dsControl">数据源控件</param>
- /// <param name="strFileName">导出的文件名</param>
- private void ExportExcel(ref System.Web.UI.WebControls.ListView dsControl, string strFileName)
- {
- strFileName = System.Web.HttpUtility.UrlEncode(strFileName, System.Text.Encoding.UTF8);
- System.Web.HttpContext.Current.Response.Clear();
- System.Web.HttpContext.Current.Response.Buffer = true;
- System.Web.HttpContext.Current.Response.Charset = "utf-8";
- System.Web.HttpContext.Current.Response.AppendHeader("Content-Disposition", "online; filename=" + strFileName + ".xls");
- System.Web.HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding("gb2312");
- System.Web.HttpContext.Current.Response.ContentType = "application/ms-excel";
- System.Globalization.CultureInfo myCItrad = new System.Globalization.CultureInfo("zh-CN", true);
- System.IO.StringWriter oStringWriter = new System.IO.StringWriter(myCItrad);
- System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
- dsControl.RenderControl(oHtmlTextWriter);
- dsControl = null;
- System.Web.HttpContext.Current.Response.Write(oStringWriter.ToString().Replace("<td", "<td STYLE='MSO-NUMBER-FORMAT:\\@'"));
- System.Web.HttpContext.Current.Response.Buffer = false;
- System.Web.HttpContext.Current.Response.End();
- }
复制代码 我是想将ListView里边的内容导出来,终于导出来Excel了,结果打开的时候提示:
请问是怎么回事?
然后打开发现,把按钮、css样式等也给导出来了
我想去除css样式,比如表头的“姓名”的背景色,
还有 “编辑”、“删除”等按钮。
请问该怎么写?
|