如何使用C#在Word中的Word自动更正选项中查找“键入时替换文本”

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

我正在尝试检查“单词替换文本列表”中是否存在单词“ CU”。我在interop.Excel和VBA中找到了,我们有AutoCorrect.ReplacementList。但是在interop.Word中不是。

所以我的问题是如何通过C#检查Word替换列表中是否存在“ CU”。感谢您的收看。enter image description here

Microsoft.Office.Interop.Word.Application oWord = (Microsoft.Office.Interop.Word.Application)w;
_activeDoc = oWord.ActiveDocument;
oWord.Application.AutoCorrect.ReplaceText .......??????
c# interop office-interop word-interop
1个回答
0
投票

要获取Word中自动更正列表的列表,请使用AutoCorrect.Entries集合。 Name属性返回“快捷方式”,Value属性返回替换“快捷方式”的文本。

string acName = "";
string acValue = "";
bool foundit = false;
Word.AutoCorrectEntries ACs = wdApp.AutoCorrect.Entries;
foreach (Word.AutoCorrectEntry AC in ACs)
{
    acName = AC.Name;
    acValue = AC.Value;
    Debug.Print("Name: {0}, Value: {1}", acName, acValue);
    if (acName == "CU")
    {
        foundit = true;
        break;
    }
}
if (foundit)
{
    MessageBox.Show("Found it: " + acValue);
}
else MessageBox.Show("Not present");
© www.soinside.com 2019 - 2024. All rights reserved.