PowerPoint Interop Assemblies Slowness Issue

随声附和 提交于 2019-12-12 19:13:40

问题


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.

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")

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.

Following are the office libraries we are using:

  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

Test Environemnt

Office 2016

Windows 8.1 + Windows 10

16 GB RAM, Intel Core i5-4570 CPU

Any solution or workaround would be highly appreciated.

PS. Also tried using Office 15.0 Object libraries

Updated

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.


回答1:


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

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.

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.

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 :)



来源:https://stackoverflow.com/questions/53004405/powerpoint-interop-assemblies-slowness-issue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!