Access and Update the Portions of Rich Text of Cell

Access and Update the Portions of Rich Text of Cell

The following code demonstrates the usage of Cell.get_characters() and Cell.set_characters() methods using the source Excel file (5112369.xlsx), which you can download from the provided link. The source Excel file contains rich text in cell A1. It has three portions, and each portion has a different font. The following code snippet accesses these portions and updates the first portion with a new font name. Finally, it saves the workbook as the output Excel file (5112366.xlsx). When you open it, you will see that the font of the first portion of the text has changed to “Arial”.

Python code to access and update the portions of rich text of a cell

Console output generated by the sample code

Here is the console output of the above sample code using the source excel file.

Before updating the font settings....
Century
Courier New
Verdana
After updating the font settings....
Arial
Courier New
Verdana