How can we concatenate two strings which are with different formats (like one in black & other in red color) to be pasted in a single cell in Excel's sheet through python code ?
from openpyxl import Workbook
from openpyxl.styles import Font
# Create a new Excel workbook
workbook = Workbook()
worksheet = workbook.active
# Write "Hello" in black
cell_hello = worksheet.cell(row=1, column=1)
cell_hello.value = "Hello"
cell_hello.font = Font(color="000000") # Black font color
# Write "world" in red
cell_world = worksheet.cell(row=1, column=2)
cell_world.value = "world"
cell_world.font = Font(color="FF0000") # Red font color
# Save the workbook
workbook.save(filename="../hello_world.xlsx")
But, how to write the data to be in a single cell ?
You can work with Rich Texts :
Output :