load_workbook: rich_test=True is ignored with read_only=True
I have openpyxl 3.1.1 installed. The MWE below first creates a single-cell worksheet with rich text (A1
is "This is a test xxx yyy"), saves it, and then opens it with rich_text=True
— once with read_only=True
and then read_only=False
. With read_only=False
, the rich text is ignored, as it opened with rich_text=False
.
import openpyxl
from openpyxl.cell.text import InlineFont
from openpyxl.cell.rich_text import TextBlock, CellRichText
rich_string1 = CellRichText('This is a test ', TextBlock(InlineFont(b=True), 'xxx'), ' yyy')
wb = openpyxl.Workbook()
wb.active['A1'] = rich_string1
wb.save('aa.xlsx')
for read_only in (True,False):
ws=openpyxl.load_workbook('aa.xlsx',rich_text=True,read_only=read_only).active
print(f'{read_only=} {type(ws["A1"].value)=}')
Output:
read_only=True type(ws["A1"].value)=<class 'str'>
read_only=False type(ws["A1"].value)=<class 'openpyxl.cell.rich_text.CellRichText'>