我知道有一個關於它的幾個線程它說簡單地使用如何從word內容中刪除html標籤?
Regex.Replace(input, "<.*?>", String.Empty);
,但我不能在寫在Word文檔文本中使用它。 我的代碼是這樣的:
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
@Transcendent,他正在處理一個Word.Document對象,而不是純文本字符串... – elgonzo
@elgonzo:是的,但這些段落可以轉換爲基本字符串,然後正則表達式的作品!我不是嗎? – Transcendent