2017-07-25 9 views
0

エクスポート中にダイナミック生成されたHTMLからハイパーリンクを削除してExcelにエクスポートします。 私はグーグルでたくさん試しましたが、まだ解決策を見つけることができませんでした。 私のコードは、私はちょうどエクスポート中にダイナミック生成されたHTMLからハイパーリンクを削除できません

HttpContext.Current.Response.Write(tw.ToString()); 

to 

HttpContext.Current.Response.Write(Regex.Replace(tw.ToString(), "</?(a|A).*?>", "")); 

から私のコードを変更し、それは私のために正常に動作します

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

です。 私の質問の解決策

関連する問題