我试图让Spellingchecked告诉我单词文档是否已进行拼写检查,但是无论我做什么,它都会返回false,我什至尝试将其更改为true并随后进行控制台日志记录,但仍然返回假。有人可以帮忙吗?这是我停留的代码块:
document = word.ActiveDocument;
Boolean SpellingChecked = document.SpellingChecked;
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine("Spelling check is set to " + (SpellingChecked ? "true" : "false"));
Console.WriteLine(fileName);
if (SpellingChecked == false)
{
document.SpellingChecked = true;
Console.WriteLine("Spelling check has now been changed to " + (SpellingChecked ? "true" : "false"));
}
答案 0 :(得分:1)
您正在混合SpellingChecked
布尔变量和文档的SpellingChecked
属性。
通过执行document.SpellingChecked = true;
,您已成功将文档的拼写检查设置为true
,但是SpellingChecked
变量未更改,因此将保留false
的值。
在任何情况下,您都可以为此跳过布尔变量:
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine("Spelling check is set to " + document.SpellingChecked);
Console.WriteLine(fileName);
if (!document.SpellingChecked)
{
document.SpellingChecked = true;
Console.WriteLine("Spelling check has now been changed to " + document.SpellingChecked);
}