C# 应用程序中与 Word 的互操作非常慢

发布于 2024-10-06 11:15:56 字数 751 浏览 0 评论 0原文

我使用VS2005,需要创建许多.doc 文件。 我的电脑(带有 2GB RAM 的 Intel c2d6600)可以每分钟转换 10 个文件,这对我来说非常慢。 我应该做什么来提高绩效?

我的代码:


oWord = new Word.Application();
oMissing = System.Reflection.Missing.Value;
oDoc = this._oWord.Documents.Add(ref oMissing, ref oMissing, ref oMissing, ref oMissing);

...
//Do something
...

//save rtf
object fileName = this.FileRtf;
object fileFormat = Word.WdSaveFormat.wdFormatRTF;
object savechanges = false;
oDoc.SaveAs(ref fileName, ref fileFormat, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing);
oWord.Quit(ref savechanges, ref oMissing, ref oMissing);

I use VS2005 and I need to create many .doc files.
My computer(Intel c2d6600 with 2gb RAM) can convert with 10 files/minute it is very slow for me.
What should I do to improve perfomance?

My code:


oWord = new Word.Application();
oMissing = System.Reflection.Missing.Value;
oDoc = this._oWord.Documents.Add(ref oMissing, ref oMissing, ref oMissing, ref oMissing);

...
//Do something
...

//save rtf
object fileName = this.FileRtf;
object fileFormat = Word.WdSaveFormat.wdFormatRTF;
object savechanges = false;
oDoc.SaveAs(ref fileName, ref fileFormat, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing);
oWord.Quit(ref savechanges, ref oMissing, ref oMissing);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

夏花。依旧 2024-10-13 11:15:56

我的心灵调试能力告诉我,你需要优化以下代码:

...
//Do something
...

My psychic debugging powers tell me that you need to optimize the below code:

...
//Do something
...
像你 2024-10-13 11:15:56

尝试减少调用次数。

oWord = new Word.Application(); 
//and 
oWord.Quit(ref savechanges, ref oMissing, ref oMissing); 

换句话说,调用一次并使用一个 Word 实例处理多个文件。

Try to reduce number of calls to

oWord = new Word.Application(); 
//and 
oWord.Quit(ref savechanges, ref oMissing, ref oMissing); 

In other words call them once and use one instance of Word for multiple files.

听闻余生 2024-10-13 11:15:56

首先,您应该分析您的应用程序以了解时间花在哪里。

有关分析器的列表,请参阅此SO问题

First, you should profile your application to find out, where the time is spent.

For is list of profilers, see this SO question.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文