我想在导出到excel期间从动态生成的HTML中删除超链接。 我通过谷歌搜索尝试了很多,但我仍然找不到解决方案。 我的代码是
string CompanyName = string.Empty;
CompanyName = Session["CompanyName"].ToString();
CompanyName = CompanyName.Replace(" ", "_");
string FileName = CompanyName.Trim() + "-Weekly_CashFlow_Statement_" +
DateTime.Now.ToString("ddMMyyyyhhmmss") + ".xls";
HttpContext.Current.Response.AppendHeader(
"Content-Disposition",
"attachment; filename=" + FileName);
HttpContext.Current.Response.Charset = "";
HttpContext.Current.Response.ContentType = "application/ms-excel";
this.Page.EnableViewState = false;
System.IO.StringWriter tw = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter(tw);
tblCashFlow.RenderControl(hw);
HttpContext.Current.Response.Write(tw.ToString());
HttpContext.Current.Response.End();
答案 0 :(得分:0)
我刚从
更改了我的代码HttpContext.Current.Response.Write(tw.ToString());
to
HttpContext.Current.Response.Write(Regex.Replace(tw.ToString(), "</?(a|A).*?>", ""));
它对我来说很好。 它解决了我的问题