[英]How to AutoFilter Excel by RGB cell color with win32com in Python
[英]How to change the color of single characters in a cell in excel with python win32com?
我对Excel的win32com绑定有疑问。 我设置了早期的绑定,并遵循了O'Reilly的“ Win32上的Python编程”一书中的一些示例。
以下代码可以正常工作:
book2.xlApp.Worksheets('Sheet1').Cells(1,1).Font.ColorIndex = 1
book2.xlApp.Worksheets('Sheet1').Cells(1,1).Font.ColorIndex = 2
它根据数字更改整个单元格的字体颜色。 但是,这不起作用:
book2.xlApp.Worksheets('Sheet1').Cells(1,1).Characters(start,length).Font.ColorIndex = 1
我得到以下回调:
Traceback (most recent call last):
File "<interactive input>", line 1, in <module>
AttributeError: Characters instance has no __call__ method
但是,在Excel VBA中,代码有效。 有人可以指出解决方案吗? 我真的需要在Excel单元格中更改字符串的一部分。
非常感谢你。
使用GetCharacters:
Cells(1,1).GetCharacters(start,length).Font.ColorIndex = 1
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.