Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/295.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用VSTO禁用Word文档中的拼写检查_C#_Ms Word_Vsto - Fatal编程技术网

C# 使用VSTO禁用Word文档中的拼写检查

C# 使用VSTO禁用Word文档中的拼写检查,c#,ms-word,vsto,C#,Ms Word,Vsto,我正在尝试使用VSTO加载项禁用当前活动Word文档中的拼写检查。我希望避免在文档的Open XML标记中保存拼写错误 我尝试使用Range.noproof属性 currentDocument.Content.NoProofing = 1; 声明应将其设置为true,但属性的类型为int。我尝试将其设置为1,但它不起作用(拼写检查错误仍然出现在文档中)。在调试器中,我看到赋值后属性仍然设置为0 如何正确使用Range.noproving属性,或者是否有其他方法禁用Word文档中的拼写检查?在使

我正在尝试使用VSTO加载项禁用当前活动Word文档中的拼写检查。我希望避免在文档的Open XML标记中保存拼写错误

我尝试使用
Range.noproof
属性

currentDocument.Content.NoProofing = 1;
声明应将其设置为
true
,但属性的类型为
int
。我尝试将其设置为
1
,但它不起作用(拼写检查错误仍然出现在文档中)。在调试器中,我看到赋值后属性仍然设置为
0


如何正确使用
Range.noproving
属性,或者是否有其他方法禁用Word文档中的拼写检查?

在使用
DocumentBeforeSave
事件保存文档之前,我忽略了所有拼写错误

this.application.DocumentBeforeSave += this.OnDocumentBeforeSave;
noproof
属性在包含拼写错误的范围上使用时似乎工作正常

private void OnDocumentBeforeSave(Document doc, ref bool saveAsUi, ref bool cancel)
{
    // Ignore all spelling errors in the document
    foreach (Range error in this.application.ActiveDocument.SpellingErrors)
    {
        error.NoProofing = 1;
    }

    // Ignore all spelling errors in content controls
    foreach (ContentControl control in this.application.ActiveDocument.ContentControls)
    {
        control.Range.NoProofing = 1;
    }
}

在使用
DocumentBeforeSave
事件保存文档之前,我忽略了所有拼写错误

this.application.DocumentBeforeSave += this.OnDocumentBeforeSave;
noproof
属性在包含拼写错误的范围上使用时似乎工作正常

private void OnDocumentBeforeSave(Document doc, ref bool saveAsUi, ref bool cancel)
{
    // Ignore all spelling errors in the document
    foreach (Range error in this.application.ActiveDocument.SpellingErrors)
    {
        error.NoProofing = 1;
    }

    // Ignore all spelling errors in content controls
    foreach (ContentControl control in this.application.ActiveDocument.ContentControls)
    {
        control.Range.NoProofing = 1;
    }
}