Because of the use of an editor, so that the data stored in the database will be mixed with some HTML tags, then the exported data will appear some different HTML tags. Seriously affect the user's visual experience (the main oneself can not see down) ...
Here's how I'm going to reassemble the DataTable and clear the HTML tags:
1 /// <summary>2 ///re-assemble the DataTable (mainly to clear the HTML tags in the DataTable data)3 /// </summary>4 /// <param name= "New_dt" >DataTable</param>5 /// <param name= "parms" >column name (can be multiple columns), such as "name", "Age"</param>6 /// <returns>the assembled DataTable</returns>7 PublicDataTable Getnewtable (DataTable New_dt,params Object[] parms)8 {9func<Object,string> fnclearhtml = (Objectobj) =//Clear HTML tag functionTen { One varHtmlstr = obj +""; A //Delete Script -Htmlstr = Htmlstr.replace ("\ r \ n",""); -Htmlstr = Regex.Replace (Htmlstr,@"<script.*?</script>","", regexoptions.ignorecase); theHtmlstr = Regex.Replace (Htmlstr,@"<style.*?</style>","", regexoptions.ignorecase); -Htmlstr = Regex.Replace (Htmlstr,@"<.*?>","", regexoptions.ignorecase); - //Delete HTML -Htmlstr = Regex.Replace (Htmlstr,@"< (. [ ^>]*) >","", regexoptions.ignorecase); +Htmlstr = Regex.Replace (Htmlstr,@"([\ r \ n]) [\s]+","", regexoptions.ignorecase); -Htmlstr = Regex.Replace (Htmlstr,@" -","", regexoptions.ignorecase); +Htmlstr = Regex.Replace (Htmlstr,@"<!--. *","", regexoptions.ignorecase); AHtmlstr = Regex.Replace (Htmlstr,@"& (quot| #34);","\"", regexoptions.ignorecase); atHtmlstr = Regex.Replace (Htmlstr,@"& (amp| #38);","&", regexoptions.ignorecase); -Htmlstr = Regex.Replace (Htmlstr,@"& (lt| #60);","<", regexoptions.ignorecase); -Htmlstr = Regex.Replace (Htmlstr,@"& (gt| #62);",">", regexoptions.ignorecase); -Htmlstr = Regex.Replace (Htmlstr,@"& (nbsp| #160);","", regexoptions.ignorecase); -Htmlstr = Regex.Replace (Htmlstr,@"& (iexcl| #161);","\xa1", regexoptions.ignorecase); -Htmlstr = Regex.Replace (Htmlstr,@"& (cent| #162);","\xa2", regexoptions.ignorecase); inHtmlstr = Regex.Replace (Htmlstr,@"& (pound| #163);","\xa3", regexoptions.ignorecase); -Htmlstr = Regex.Replace (Htmlstr,@"& (copy| #169);","\xa9", regexoptions.ignorecase); toHtmlstr = Regex.Replace (Htmlstr,@"(\d+);","", regexoptions.ignorecase); +Htmlstr = Htmlstr.replace ("<",""); -Htmlstr = Htmlstr.replace (">",""); theHtmlstr = Htmlstr.replace ("\ r \ n",""); *Htmlstr =HttpContext.Current.Server.HtmlEncode (HTMLSTR). Trim (); $ returnHtmlstr;Panax Notoginseng }; - if(New_dt! =NULL) the { + foreach(varPinchparms) A { the varPP = p +""; +New_dt. Columns.Add (P +"1",typeof(string)); - foreach(DataRow DrinchNew_dt. Rows) $Dr[p +"1"] =fnclearhtml (dr[pp]); $ - New_dt. Columns.remove (PP); -New_dt. Columns[p +"1"]. ColumnName =pp; the } - }Wuyi returnNew_dt; the}
Where the fnclearhtml function is specifically to clear the HTML tag function, but the small master in writing the following delete column when the NEW_DT found. Columns.remove (PP) This code simply deletes the column's data and the column's name, and the column will appear with other names such as Column1 or COLUMN2, the total number of columns is still so many ...
Hope to see the great God of the classical writings of the Little Lord, to give some answers to the small master.
The Little Lord is grateful ....
How C # Clears HTML tags in strings ...