【发布时间】:2020-03-28 07:19:19
【问题描述】:
我使用 word interop 打开了一个 word 文档,并添加了几段文本。这些长度取决于一系列因素。然后我像这样在下标中添加一行包含 CR 的文本(字母 CR 的下标不包含在 Unicode 下标中):
Dim word As Word.Application = New Word.Application()
Dim doc As Word.Document
'more code inserting paragraphs here
Dim Paratext as string
Paratext = "Elastic Critical Buckling Load N_CR=(π² (E/Yₘ )I)/(L_CR∙L² )"
para0 = doc.Content.Paragraphs.Add
para0.Range.Text = Paratext
para0.Range.InsertParagraphAfter()
para0.Range.Style = doc.Styles("Normal")
Dim Rstart As Int16 = Paratext.IndexOf("CR")
Dim Rend As Int16 = Paratext.IndexOf("=")
' this is wrong: I select the range in the document
' using the location in the paragraph.
Dim SRange = doc.Range(Rstart, Rend)
SRange.Select()
Dim currentselection As Word.Selection = word.Selection
currentselection.Font.Subscript = 1
编辑:我选择了错误的文本。我正在识别刚刚添加的段落中字母 CR 的位置,并将其应用于已经添加了多个段落的文档。因此,文档索引 35 和 36 处的两个字符而不是段落成为下标。 如何获取我刚刚添加的段落开头的索引?
【问题讨论】:
-
它给出了什么错误?
-
没有错误,只是不会改变文本
-
我已经意识到我哪里出错了。我已经确定了段落中“CR”的位置,然后将该范围应用于整个文档。如何在段落中选择范围?
标签: vb.net office-interop