清除WORD格式HTML垃圾样式
2008-08-21 16:00
501 查看
static string CleanWordHtml(string html)
{
StringCollection sc = new StringCollection();
// get rid of unnecessary tag spans (comments and title)
sc.Add(@"<!--(/w|/W)+?-->");
sc.Add(@"<title>(/w|/W)+?</title>");
// Get rid of classes and styles
sc.Add(@"/s?class=/w+");
sc.Add(@"/s+style='[^']+'");
// Get rid of unnecessary tags
//sc.Add(@"<(meta|link|/?o:|/?style|/?div|/?st/d|/?head|/?html|body|/?body|/?span|!/[)[^>]*?>");
sc.Add(@"<(meta|link|/?o:|/?style|/?font|/?strong|/?st/d|/?head|/?html|body|/?body|/?span|!/[)[^>]*?>");
// Get rid of empty paragraph tags
sc.Add(@"(<[^>]+>)+ (<//w+>)+");
// remove bizarre v: element attached to <img> tag
sc.Add(@"/s+v:/w+=""[^""]+""");
// remove extra lines
sc.Add(@"(/n/r){2,}");
foreach (string s in sc)
{
html = Regex.Replace(html, s, "", RegexOptions.IgnoreCase);
}
return html;
}
{
StringCollection sc = new StringCollection();
// get rid of unnecessary tag spans (comments and title)
sc.Add(@"<!--(/w|/W)+?-->");
sc.Add(@"<title>(/w|/W)+?</title>");
// Get rid of classes and styles
sc.Add(@"/s?class=/w+");
sc.Add(@"/s+style='[^']+'");
// Get rid of unnecessary tags
//sc.Add(@"<(meta|link|/?o:|/?style|/?div|/?st/d|/?head|/?html|body|/?body|/?span|!/[)[^>]*?>");
sc.Add(@"<(meta|link|/?o:|/?style|/?font|/?strong|/?st/d|/?head|/?html|body|/?body|/?span|!/[)[^>]*?>");
// Get rid of empty paragraph tags
sc.Add(@"(<[^>]+>)+ (<//w+>)+");
// remove bizarre v: element attached to <img> tag
sc.Add(@"/s+v:/w+=""[^""]+""");
// remove extra lines
sc.Add(@"(/n/r){2,}");
foreach (string s in sc)
{
html = Regex.Replace(html, s, "", RegexOptions.IgnoreCase);
}
return html;
}
相关文章推荐
- 用JS清除word保存为html格式后产生的垃圾代码
- 清除Word转html的垃圾代码
- 正则表达式去掉word转为html后的垃圾样式
- java 清除 HTML标签格式、CSS 样式
- JAVA:借用OpenOffice将上传的Word文档转换成Html格式
- 15-07-27 HTML-样式-格式与布局
- 将Word文档转化为HTML格式的文档
- JAVA清除html格式正则表达式
- ireport导出各种格式(pdf,excel,word,html,print)
- React 如何解析从后台读取的内容是html格式代码(带样式)
- 用C#去除字符串中HTML的格式(清除数据库中html标签)
- Word 格式 样式
- tinyMCE粘贴word/html时去掉文本里的样式
- JAVA:借用OpenOffice将上传的Word文档转换成Html格式
- ASP.NET将Word文档转化为HTML格式的文档
- html页面中写css样式基本格式
- 清除数据库中的HTML格式
- android 资源文件string.xml字符支持HTML样式和格式
- 清除数据库中的HTML格式
- FckEditor中从word文档粘贴过来的内容在点击确定清除格式后直接清除而不是再弹出从MS WORD粘贴对话框