【发布时间】:2014-06-29 21:44:07
【问题描述】:
我知道有几个关于它的线程说只是使用
Regex.Replace(input, "<.*?>", String.Empty);
但我不能在用 word doc 编写的文本中使用它。 我的代码是这样的:
Microsoft.Office.Interop.Word.Document wBelge = oWord.Documents.Add(ref oMissing,
ref oMissing, ref oMissing, ref oMissing);
Microsoft.Office.Interop.Word.Paragraph paragraf2;
paragraf2 = wBelge.Paragraphs.Add(ref oMissing);
paragraf2.Range.Text ="some long text";
我可以通过查找和替换来改变
Word.Find findObject = oWord.Selection.Find;
findObject.ClearFormatting();
findObject.Text = "<strong>";
findObject.Replacement.Text = "";
findObject.Replacement.ClearFormatting();
object replaceAllc = Word.WdReplace.wdReplaceAll;
findObject.Execute(ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref replaceAllc, ref oMissing, ref oMissing, ref oMissing, ref oMissing);
我需要对每个 html 标签都这样做吗?
【问题讨论】:
-
如果正则表达式失败(我不明白为什么会失败,你能说明你是如何使用它的吗?),你可以创建一个所有标签的列表并使用 for 循环删除所有标签。
-
@Transcendent,他正在处理 Word.Document 对象,而不是纯文本字符串...
-
@elgonzo:是的,但是这些段落可以转换为基本字符串,然后正则表达式有效!我说的不对吗?
-
@Transcendent,我猜他是在谈论他的文档内容中的 HTML 标签(作为文本的一部分),而不是关于 OOXML...
-
@Transcendent,别介意。这就是著名的“周末心态”。我经常处于那种状态;)
标签: c# html ms-word office-interop