上传的 Word 文档中的新行标记是什么?

发布于 2024-08-03 14:05:25 字数 714 浏览 2 评论 0原文

我正在尝试上传 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夜血缘 2024-08-10 14:05:25

您是否尝试过使用回车符而不是换行符?不知道它是否有效,但我刚刚在 notepad++ 中打开了一个 .doc 文件,行之间用一个回车符分隔,ControlChars.NewLine 由 \cr + 0 组成。

strArticle = Regex.Replace(strArticle, ControlChars.Cr, "<BR>")

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.

strArticle = Regex.Replace(strArticle, ControlChars.Cr, "<BR>")
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文