我正在尝试上传Word文档,然后在HTML中逐行编写。我对Microsoft Word对象库进行了引用。然后我使用以下代码来获取并将其放入字符串变量中。但是,我尝试了多个正则表达式语句用“
”替换新行字符,但我尝试过的任何内容都没有...
Dim wordApp As New Microsoft.Office.Interop.Word.Application
Dim wordDoc As New Microsoft.Office.Interop.Word.Document
Dim file As Object = "C:\test.doc"
Dim nullobj As Object = System.Reflection.Missing.Value
wordDoc = wordApp.Documents.Open(file, nullobj, nullobj, nullobj, nullobj, nullobj, nullobj, nullobj, nullobj, nullobj, nullobj, nullobj)
Dim strArticle As String = wordDoc.Content.Text
'It's not finding the new line marker here
strArticle = Regex.Replace(strArticle, ControlChars.NewLine, "<BR>")
答案 0 :(得分:0)
您是否尝试使用回车代替新线?不知道它是否可行,但我只是在notepad ++中打开一个.doc文件,并且这些行用一个回车符分隔,而ControlChars.NewLine由\ cr + 0组成。
strArticle = Regex.Replace(strArticle, ControlChars.Cr, "<BR>")