首页 > 解决方案 > 有没有办法从 vb.net 中的 Word doc (2016) 中解析出下标和上标

问题描述

这听起来很简单,但我似乎无法找到一种方法来使用 vb.net 解析出 Word (2016) 中包含下标或上标的整个单词。我有一个 Word 文档,想用下标/上标解析所有单词,并将其保存在一个数组中以供下游的其他进程使用。请参阅下面的附加屏幕截图。

因此,如果代码从上到下读取,它会遇到的第一个具有下标/上标的单词是 R 1然后是 (CH 2 ) m CH 3,依此类推,将它们保存到一个数组中 - 想要获取整个包含下标/上标的单词 - [即:regex("\b(\w+)\b")]

尝试使用 if 语句检查下标/上标是否存在,但是一旦将其读入代码中,它就变成了常规字符,找不到匹配项,请参见下面的第二个屏幕截图。

有谁知道用下标/上标解析整个单词是否可行?提前致谢。

在此处输入图像描述

在此处输入图像描述

   DEF_SUPERSCRIPT = "R¹X"

        'loop through all of the paragraphs
        For N = 1 To totalparagraphs
            loopcount = loopcount + 1
            newind = "No"

            'read content of each line - but it came in as regular character 1 instead of superscript 1
            content = Application.Selection.Paragraphs(N).Range.Text

            'here is where - trying to determine if it could catch the line that has subscripts/superscrpits - but no match to be found
            If (Application.Selection.Paragraphs(N).Range.Text.Contains(DEF_SUPERSCRIPT)) Then
                MessageBox.Show("...found superscript here 1...", Msg_Title & SPACER2_MSGTITLE & "[" & Now() & "]", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
            End If
         Next

标签: vb.netoffice-interopoffice-addins

解决方案


推荐阅读