无法获取Excel ChartObjects计数 [英] Can't get Excel ChartObjects Count

查看:751
本文介绍了无法获取Excel ChartObjects计数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有人知道如何获取Excel ChartObjects计数?
在VBA示例中,我可以在一个表中获取所有图表名称和图表计数。
但是我不知道为什么,python不能得到图表计数。我尝试所有其他ChartObjects属性,除Count之外的所有工作。

Is there anyone know how to get Excel ChartObjects Count? In VBA example, I can get all the Chart name and chart count in one sheet. but I don't know why , python can't get charts count. I try all other ChartObjects property, all work except Count.

[MSDN Library][1]
ChartObjects.Application Property (Excel)
Not Working ===> ChartObjects.Count Property (Excel)
ChartObjects.Creator Property (Excel)
ChartObjects.Height Property (Excel)
ChartObjects.Left Property (Excel)
ChartObjects.Locked Property (Excel)
ChartObjects.Parent Property (Excel)
ChartObjects.Placement Property (Excel)
ChartObjects.PrintObject Property (Excel)
ChartObjects.ProtectChartObject Property (Excel)
ChartObjects.ShapeRange Property (Excel)
ChartObjects.Top Property (Excel)
ChartObjects.Visible Property (Excel)
ChartObjects.Width Property (Excel)

ex.
Python:
   workbook.Sheets(2).ChartObjects.Count

VBA:
   ActiveWorkbook.Sheets(lngS).ChartObjects.Count

Python错误:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "F:\Python27\lib\site-packages\win32com\client\__init__.py", line 465, in
 __getattr__
    raise AttributeError("'%s' object has no attribute '%s'" % (repr(self), attr
))
AttributeError: '<win32com.gen_py.Microsoft Excel 14.0 Object Library.ChartObjec
t instance at 0x51078984>' object has no attribute 'Count'

  [1]: http://msdn.microsoft.com/en-us/library/ff846604%28v=office.14%29.aspx


推荐答案

回答我的问题:
ChartObjects是一个函数。所以不能有count属性。
下面的代码段解决了Python和Visual Basic中的问题。

Answer my question: The ChartObjects is a function. so can't have count attribute. Below code segment fixs the issue in both Python and Visual Basic.

注意,VBA不需要这一步。

Note, VBA doesn't need this step.

Python or VB:
oWorksheet = workbook.Worksheets("Created.vs.Resolved")
oChart = oWorksheet.ChartObjects()
chart_count = oChart.Count

VBA: 
ActiveWorkbook.Sheets(lngS).ChartObjects.Count

这篇关于无法获取Excel ChartObjects计数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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