How to put Style in the middle of a string?
Question:
Answers:
Openpyxl doesn’t have released option to do this currently but you can do it with Xlwings using the characters attribute.
import xlwings as xw
wb = xw.Book('foo.xlsx')
ws = wb.sheets('Sheet1')
ws['A2'].value = "I want to put the style in the string"
ws['A2'].font.size = 9
ws['A2'].font.name = 'Consolas'
ws['A2'].characters[10:13].font.bold = True
ws['A2'].characters[18:23].font.color = (255, 0, 0)
wb.save()
wb.close()
Openpyxl doesn’t have released option to do this currently but you can do it with Xlwings using the characters attribute.
import xlwings as xw
wb = xw.Book('foo.xlsx')
ws = wb.sheets('Sheet1')
ws['A2'].value = "I want to put the style in the string"
ws['A2'].font.size = 9
ws['A2'].font.name = 'Consolas'
ws['A2'].characters[10:13].font.bold = True
ws['A2'].characters[18:23].font.color = (255, 0, 0)
wb.save()
wb.close()