首页 > 解决方案 > 在python中从excel中提取图表

问题描述

我想使用python代码从excel文件中提取图表作为图像

from win32com.client import Dispatch
excel = Dispatch("Excel.Application")
workbook = excel.ActiveWorkbook
xlsWB = excel.Workbooks.Open(r'D:\\indexing\\test.xlsx') 
xlsSheet = xlsWB.Sheets("sheet1") 
mychart = excel.Charts(1)
mychart.Export(Filename=r'D:\\indexing\\test.xlsx.png')

这是错误 iam gettig
错误:

com_error                                 Traceback (most recent call last)
<ipython-input-31-95633a655eb6> in <module>
  9 xlsSheet = xlsWB.Sheets("sheet1")
 10 
 ---> 11 mychart = excel.Charts(1)  #'1' is the index of the chart object in
 12 
 13 mychart.Export(Filename=r'D:\\indexing\\test.xlsx.png')

 ~\Anaconda3\lib\site-packages\win32com\client\dynamic.py in __call__(self, *args)
195                 if invkind is not None:
196                         allArgs = (dispid,LCID,invkind,1) + args
--> 197                         return self._get_good_object_(self._oleobj_.Invoke(*allArgs),self._olerepr_.defaultDispatchName,None)
198                 raise TypeError("This dispatch object does not define a default method")
199 

com_error: (-2147352567, 'Exception occurred.', (0, None, None, None, 0, -2147352565), None)

标签: excelpython-3.xcharts

解决方案


推荐阅读