简体   繁体   English

使用 win32com 控制 Excel 我需要更新数据点的颜色,但它们似乎是只读的

[英]Using win32com to control Excel and I need to update the color of Data Points but they seem to be read only

wb = excel.Workbooks.Open(f"C:\\Users\\user\\Downloads\\EXCEL\\Credits_Query.xlsx")
ws=wb.Sheets("OEM Pivot")
chart = ws.ChartObjects(1).Chart
chart.SeriesCollection(1).XValues

Returns: ('NTK553FAE5', '8DG62496AA', 'TOM-100G-Q-LR4', 'ORM-CXH1', ...)返回:(“NTK553FAE5”、“8DG62496AA”、“TOM-100G-Q-LR4”、“ORM-CXH1”……)

chart.SeriesCollection(1).Points(1).Fill.ForeColor.RGB

Returns: 39423退货:39423

But it appears to be readonly.但它似乎是只读的。

>>> chart.SeriesCollection(1).Points(1).Fill.ForeColor.RGB = 50
Traceback (most recent call last):
File "C:\Users\user\AppData\Roaming\Python\Python39\site-packages\win32com\client\__init__.py", line 590, in __setattr__
args, defArgs = self._prop_map_put_[attr]
KeyError: 'RGB'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\jepal\AppData\Roaming\Python\Python39\site-packages\win32com\client\__init__.py", line 592, in __setattr__
raise AttributeError(
AttributeError: '<win32com.gen_py.Microsoft Excel 16.0 Object Library.ChartColorFormat 
instance at 0x2231402656864>' object has no attribute 'RGB'

I also tried several variations of: chart.SeriesCollection(1).Points(1).Fill.ForeColor.RGB.我还尝试了以下几种变体:chart.SeriesCollection(1).Points(1).Fill.ForeColor.RGB。 setattr设定值

But no luck, is it possible to change the color of the Data Points?但运气不好,是否可以更改数据点的颜色?

As usual, hours of researching with no luck, and 2 min after I post I find the answer.像往常一样,研究了几个小时都没有运气,在我发布后 2 分钟我找到了答案。

chart.SeriesCollection(1).Points(3).Fill.ForeColor.SchemeColor = 47

This allows you to change the color of the individual points.这允许您更改各个点的颜色。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM