上传的 Word 文档中的新行标记是什么?
我正在尝试上传 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>")
I am attempting to uplaod a Word doc and then write it line by line in HTML. I made a referecne to the Microsoft Word Object Library. Then I use the following code to grab the and put it in a string variable. However, I have tried multiple regex statements to replace the new line character with "
" but nothing I have tried has worked...
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>")
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否尝试过使用回车符而不是换行符?不知道它是否有效,但我刚刚在 notepad++ 中打开了一个 .doc 文件,行之间用一个回车符分隔,ControlChars.NewLine 由 \cr + 0 组成。
Have you tried using a carriage return instead of new line? Dunno if it will work or not, but I just opened a .doc file in notepad++ and the lines were delimited with a single carriage return, and ControlChars.NewLine is composed of \cr + 0.