2013年2月1日 星期五

[Python] Get Excel Chart Count in all WorkSheets




# -*- coding: utf-8 -*-
import win32com
from win32com.client import DispatchEx, constants
msexcel = DispatchEx('Excel.Application')
msexcel.Visible = 1
msexcel.DisplayAlerts = 0
report_template_xlsx=u'ABC.xlsm'
workbook = msexcel.Workbooks.Open(report_template_xlsx)
sheet_count = workbook.Sheets.Count
print "Sheet #: " + str(sheet_count)
#print "Chart #: " + str(chart_count)
#workbook.Close()
#msexcel.Quit()
#quit()
for lngS in range(1,sheet_count+1):
  oWorksheet = workbook.Sheets(lngS)
  #oWorksheet = workbook.Worksheets("Created.vs.Resolved")
  oChart = oWorksheet.ChartObjects()
  chart_count = oChart.Count
  print "oWorksheet [" + str(oWorksheet.Name) + "] Chart count#: " + str(chart_count)

workbook.Close()
msexcel.Quit()

沒有留言: