PowerPoint互操作程序集慢度问题 [英] PowerPoint Interop Assemblies Slowness Issue

查看:100
本文介绍了PowerPoint互操作程序集慢度问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用MS Office互操作程序集构建一个Powerpoint插件,该插件可以动态插入幻灯片和图表.但是在插入过程中,最多需要20秒才能完成从插入幻灯片到插入图表的过程.

I'm using MS Office interop assemblies to build a Powerpoint addin that inserts slides and charts on the fly. But during insertion it take up to 20 seconds to complete the process from inserting the slide to insertion of the chart.

进行大量日志记录后,我注意到几行代码使我们的应用程序停留了20秒钟以上. 这些行如下:

After doing extensive logging, I noticed few lines of code where our application gets stuck for 20+ seconds. Here are those lines:

powerpointChartObj.SetSourceData(Source:=String.Format("=Sheet1!A1:B{0}", 5))

powerpointSlideObject.Shapes("some shape name")

在幻灯片插入过程中,我们不断地使用PowerPoint图表和幻灯片对象,但有时它们会在上述行之一中被阻塞.而且它在哪条线上受阻是随机的.

We continuously play with PowerPoint chart and slide objects during the slide insertion process but some time it gets blocked on one of above lines. And it's random on which line it gets blocked.

以下是我们正在使用的办公室图书馆:

  1. Microsoft Office 16.0对象库
  2. Microsoft Excel 16.0对象库
  3. Microsoft Graph 16.0对象库
  4. Microsoft PowerPoint 16.0对象库
  5. Microsoft Word 16.0对象库
  6. Microsoft.Office.Tools.dll
  7. Microsoft.Office.Tools.Common.dll
  8. Microsoft.Office.Tools.Common.v4.0.Utilities.dll
  9. Microsoft.Office.Tools.v4.0.Framework.dll
  10. Microsoft.Vbe.Interop
  1. Microsoft Office 16.0 Object Library
  2. Microsoft Excel 16.0 Object Library
  3. Microsoft Graph 16.0 Object Library
  4. Microsoft PowerPoint 16.0 Object Library
  5. Microsoft Word 16.0 Object Library
  6. Microsoft.Office.Tools.dll
  7. Microsoft.Office.Tools.Common.dll
  8. Microsoft.Office.Tools.Common.v4.0.Utilities.dll
  9. Microsoft.Office.Tools.v4.0.Framework.dll
  10. Microsoft.Vbe.Interop

测试环境

Office 2016

Office 2016

Windows 8.1 + Windows 10

Windows 8.1 + Windows 10

16 GB RAM,英特尔酷睿i5-4570 CPU

16 GB RAM, Intel Core i5-4570 CPU

任何解决方案或解决方法都将受到高度赞赏.

Any solution or workaround would be highly appreciated.

PS.还尝试使用Office 15.0对象库

PS. Also tried using Office 15.0 Object libraries

已更新

我已经尝试过EnableEvents并将其永远设置为false.它可以在图表插入/更新方案期间提高性能,但是如果我们连续调用PowerPoint COM组件(例如,形状,幻灯片等以操纵PowerPoint的东西),PowerPoint将再次卡住约20秒.不确定在PowerPoint互操作中是否有与EnableEvents类似的东西.

I've tried EnableEvents and set it false forever. It boost up the performance during chart insertion/update scenarios but if we continuously make calls to PowerPoint COM components(e.g. Shapes, slides etc. to manipulate PowerPoint things), PowerPoint gets stuck for around 20 seconds again. Not sure if there is anything similar to EnableEvents available in PowerPoint interop.

推荐答案

我还没有发表评论的权利,所以如果这不是完美的答案,请多多包涵.

I don't have the rights to comment yet, so bear with me if this is not the perfect answer.

我在办公产品自动化方面的经验是通过VBS,但是它们都使用COM对象,因此它的工作原理可能相同.我主要使用Excel,因此powerpoint并不是我最强的方面.

My experience with automation with office products is through VBS, but they both uses the COM-objects, so it probably works the same. I mostly use Excel, so powerpoint is not my strongest side.

我的建议是在添加数据时暂时禁用屏幕更新/事件.

My suggestion is to temporary disable screenupdates/events while adding data.

这是一个示例(使用VBS):

Here is an example (using VBS):

Application.Calculation = xlCalculationManual 'Excel specific
Application.ScreenUpdating = False 'All office products
Application.DisplayStatusBar = False 'All office products
Application.EnableEvents = False 'All office products
'your code running here
Application.EnableEvents = True 'All office products
Application. DisplayStatusBar = True 'All office products
Application.ScreenUpdating = True 'All office products
Application.Calculation = xlCalculationAutomatic 'Excel specific

还避免在数据中使用大量选择"调用,因为这会降低速度.

Also avoid using a lot "select" calls in data, since it slows things down.

在我的VBS脚本中,通过使用这种技术,我几乎没有滞后或出现问题.我还建议您在添加大量数据的同时创建自己的请稍候"弹出屏幕.对于某些呼叫,即使您在Powerpoint/Excel中手动进行,也要花费一些时间.

In my VBS scripts I got more or less no lag or problems by using this technique. I would also suggest that you create your own "please wait" popup screen while adding alot of data. For some calls do take time, even if you do it manually in Powerpoint / Excel.

祝你好运,办公室自动化可能会令人生厌:)

Good luck, office automation can be a hazzle :)

这篇关于PowerPoint互操作程序集慢度问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆