我需要去除特定位置的Word HTML标记。目前,我这样做:现在我剥整个HTML为<p>
标签与sc.Add(@"<p> </p>");
Strip Word Html Tags
public string CleanWordStyle(string html)
{
StringCollection sc = new StringCollection();
sc.Add(@"<table\b[^>]*>(.*?)</table>");
sc.Add(@"(<o:|</o:)[^>]+>");
sc.Add(@"(<v:|</v:)[^>]+>");
sc.Add(@"(<st1:|</st1:)[^>]+>");
sc.Add(@"(mso-bidi-|mso-fareast|mso-spacerun:|mso-list: ign|mso-ascii|mso-hansi|mso-ansi|mso-element|mso-special|mso-highlight|mso-border|mso-yfti|mso-padding|mso-background|mso-tab|mso-width|mso-height|mso-pagination|mso-theme|mso-outline)[^;]+;");
sc.Add(@"(font-size|font-family):[^;]+;");
sc.Add(@"font:[^;]+;");
sc.Add(@"line-height:[^;]+;");
sc.Add(@"class=""mso[^""]+""");
sc.Add(@"times new roman","serif";");
sc.Add(@"verdana","sans-serif";");
sc.Add(@"<p> </p>");
sc.Add(@"<p> </p>");
foreach (string s in sc)
{
html = Regex.Replace(html, s, "", RegexOptions.IgnoreCase);
}
html = Regex.Replace(html, @" ", @" "); //can not be read by as XmlDocument if not!
return html;
}
,但我要的是:如果我打表的标签,应立即停止更换,直到达到一个表结束标签。可能吗?
我给出一个解决方案,但现在,我再想一想,是删除和格式化这个词,只是不停的文字...我不知道,如果是你的样子因为,但HTMLAgilityPack的使用是这个想法。 – Aristos 2012-07-06 08:41:24
我的定制者希望不要触摸桌子标签内的所有东西,但其他所有东西都应该剥离。它不是我正在寻找的解决方案 – Timsen 2012-07-06 08:44:46
看看HTMLAgilityPack,这是个想法,这可以给你DOM,并从那里你可以保留你想要的部分。 – Aristos 2012-07-06 08:45:33