0

使用下面的代码基本上我正在逐字检查文档并分离正确的文档。我工作,但太慢了,我必须等待 10 多分钟才能写 4 万字。当我打开同一个文档时,Word 会在几秒钟内对其进行检查。我究竟做错了什么?

var application = new Application();
        application.Visible = false;
        Document document = application.Documents.Open("C:\\Users\\hrzafer\\Desktop\\spellcheck.docx");

        // Loop through all words in the document.
        int count = document.Words.Count;
        IList<string> corrects = new List<string>();
        for (int i = 1; i <= count; i++)
        {
            if (document.Words[i].SpellingErrors.Count == 0)
            {
                string text = document.Words[i].Text;
                corrects.Add(text);
            }
        }

        File.WriteAllLines("corrects.txt", corrects);
        application.Quit();
4

1 回答 1

0

一种解决方法,因为您似乎只需要文档中的正确单词:

for i=ActiveDocument.Range.SpellingErrors.Count to 1 step -1
    ActiveDocument.Range.SpellingErrors(i).Delete
next

然后用新名称保存文档

ActiveDocument.SaveAs FileName:="C:\MyWordDocs\NewFile.docx", _ 
    FileFormat:=wdFormatXMLDocument
于 2012-07-25T15:37:28.570 回答