1

I have written a method in IronPython that writes to a PowerPoint chart using the Interop.PowerPoint library. The method works fine, however it encounters performance issues when dealing with a PPT file with a lot of charts. I have determined that the cause for this is due to the fact that each time I write to a chart, an instance of Excel is opened, but never closed/released (thereby taking up memory resources). I have not been able to figure out how to close/release the instance of Excel. Can you please help?

Here's the relevant code:

#edit chart values
my_chart = shp.Chart
my_chart_data = my_chart.ChartData
my_chart_wb = my_chart_data.Workbook
my_chart_ws = my_chart_wb.Worksheets(1)
my_chart_ws.Range("B2").Value = record[shp.Name]

#close Excel (LINE EXECUTES, BUT EXCEL REMAINS OPEN IN THE TASK MANAGER)
my_chart_wb.Close
my_chart_wb.Application.Quit()
KingOfTheNerds
  • 653
  • 1
  • 6
  • 19
  • 1
    this is for c# but it is the same concept http://stackoverflow.com/questions/158706/how-to-properly-clean-up-excel-interop-objects – chancea Jan 27 '15 at 22:05
  • Thanks @chancea - part of the problem that I'm having in implementing solutions that I've seen is that I don't expressly create any sort of Excel Application object. I've tried adding `System.Runtime.InteropServices.Marshal.ReleaseComObject(my_chart_wb)`, but that just causes an error. – KingOfTheNerds Jan 27 '15 at 22:30
  • Just one other note, it looks like performance is better when you have these couple of lines in the script, however Excel itself still does not necessarily close. – KingOfTheNerds Jan 27 '15 at 22:36
  • try putting `my_chart_data.Activate()` after `my_chart_data = my_chart.ChartData` – Kyle G Mar 13 '17 at 19:16

0 Answers0