'How can I add a strikethrough to a piece of text using xlwings in python?

I am able to add a strikethrough to the entire string in Excel cell A1 using xlwings in python with the following code.

ws.range('A1').api.Font.Strikethrough = True

When I try to apply this and add a strikethrough only for the third character from the first in cell A1, I get the following error when I run the code below.

ws.range('A1').api.Characters(1, 3).Font.Strikethrough = True

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Input In [40], in <cell line: 1>()
----> 1 ws.range('A1').api.Characters(1, 3).Font.Strikethrough = True

File c:\users\******\appdata\local\programs\python\python38\lib\site-packages\xlwings\_xlwindows.py:169, in COMRetryObjectWrapper.__call__(self, *args, **kwargs)
    167 for i in range(N_COM_ATTEMPTS + 1):
    168     try:
--> 169         v = self._inner(*args, **kwargs)
    170         if isinstance(v, (CDispatch, CoClassBaseClass, DispatchBaseClass)):
    171             return COMRetryObjectWrapper(v)

TypeError: 'Characters' object is not callable

How can I use xlwings in python to add a strikethrough to some of the characters?

Windows 10 /Python 3.8.9



Solution 1:[1]

As per Shrotter's comment, the code below did what I wanted!

ws.range('A1').api.GetCharacters(1, 3).Font.Strikethrough = True

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 aosae