【问题标题】:Word Interop spellchecking a document word by word is too slowWord Interop 逐字逐句检查文档太慢
【发布时间】:2012-07-25 23:37:42
【问题描述】:

使用下面的代码,我基本上是逐字检查文档并将正确的分开。我工作,但太慢了,我必须等待 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();

【问题讨论】:

    标签: interop ms-word spell-checking


    【解决方案1】:

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

    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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-07-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多