I'm looking for a solution to combine same text color excel cells into a single cell in a column. The following image shows the input_excel.xlsx :-
The output_excel.xlsx should be returned by python code as follows:-
I looked into the following link: Subsetting a dataframe based on cell color and text color in excel sheet but not able to combine the cells that are having black text color.
The following code was implemented to detect red text and black text in an excel:-
# importing openpyxl module
import openpyxl
# Give the location of the file
path = "E:\\input_excel.xlsx"
# workbook object is created
wb_obj = openpyxl.load_workbook(path)
sheet_obj = wb_obj.active
m_row = sheet_obj.max_row
for i in range(1, m_row + 1):
cell_obj = sheet_obj.cell(row = i, column = 1).font.color
if cell_obj is not None: # to catch cells that do have a color object
if cell_obj.rgb == "FFFF0000":
print(cell_obj.rgb)
elif cell_obj.rgb == "00000000":
print(cell_obj.rgb)
The above code always returns the red text hex value as follows:-
FFFF0000
FFFF0000
FFFF0000
FFFF0000
FFFF0000
Why does openpyxl not detect black color text? How can the code be improved? Can anybody help in implementing the code needed for above shown images?