使用 Microsoft.Office.Interop.Word 对插入的文本应用自动更正

问题描述 投票:0回答:0

当我使用

Microsoft.Office.Interop.Word
将文本插入 Word 时,插入的文本不会应用自动更正。

例如,我在 Word 中有一个自动更正功能,它应该将

auto correct
更改为
AUTO CORRECT
.

string text = "is this auto correct? Is this auto format 1/2?";
int start = word.Selection.Start;
word.Selection.TypeText(text);
int end = word.Selection.Start;
Microsoft.Office.Interop.Word.Range insertedRange = word.ActiveDocument.Range(start, end);
insertedRange.AutoFormat();

// In Word the text will come over as:
// Actual:   "is this auto correct? is this auto format ½?"
// Expected: "Is this AUTO CORRECT? Is this auto format ½?"
//            ^       ^^^^ ^^^^^^^  ^

自动格式有效,Word 会将

1/2
更改为
½
。但是 Word 不会将
auto correct
更改为
AUTO CORRECT
.

我找不到对我插入的文本应用自动更正的功能。 Range好像没有这样的功能

我最接近的是自己枚举所有自动更正并在必要时应用自动更正见此处。 但是这种方法不包括

Capitalize first letter of sentences
和 Word 中的其他此类自动更正功能。

如果我手动将我的插入符号放在

auto correct
文本旁边并按
<space>
文本将变为
AUTO CORRECT
,我需要一种从代码触发它的方法。

如何对我插入的文本应用自动更正?

c# ms-word office-interop office-automation autocorrect
© www.soinside.com 2019 - 2024. All rights reserved.