![](/img/trans.png)
[英]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.