>Word.ApplicationClass WordApp = new Word.ApplicationClass();
>Word.Range wr = WordApp.Selection.Range;
>gramcount = wr.GrammaticalErrors.Count;
>
>for(i=1;i<=gramcount;i++)
>{
> errorword = wr.GrammaticalErrors.Item(i).Text.ToString();
>}
If you cache the GrammaticalErrors collection, you save one call per
iteration, which could make a difference (since marshaling and the
managed<->unmanaged transition makes interop calls slower then pure
managed calls). So try
Word.ProofreadingErrors grammaticalErrors = wr.GrammaticalErrors;
for(i=1;i<=gramcount;i++)
{
errorword = grammaticalErrors.Item(i).Text.ToString();
}
引文来源 WORD DOM performance in c#
================================================================
Word自动化,真是个头痛的事儿。