I'm working on a function to edit old "xls" files, not "xlsx". I'm using packages like xlrd, xlutils and xlwt. I want change the color of a cell without change other style like Bold and Center. The color is user defined RGB color based on the input of the user.
I write some code like this, but I cannot find a way to transfer the style information from "xlrd.formatting.XF" to "xlwt.Style.XFStyle". So, my code will lose the style information.
reader_book = xlrd.open_workbook(self.filePath, formatting_info=True)
reader_sheet = reader_book.sheet_by_name(self.sheetName)
writer_book = copy(reader_book)
writer_sheet_index = [s.name for s in reader_book.sheets()].index(self.sheetName)
writer_sheet = writer_book.get_sheet(writer_sheet_index)
reader_cell = reader_sheet.cell(rowx=int(row_str)-1, colx=int(col_str)-1)
print("reader_cell.xf_index is", reader_cell.xf_index)
fmt = reader_book.xf_list[reader_cell.xf_index]
print("type(fmt) is", type(fmt))
print("fmt.dump():", fmt.dump())
xlwt.add_palette_colour("custom_colour", 0x21)
writer_book.set_colour_RGB(0x21, 244, 0, 0)
style = xlwt.easyxf('pattern: pattern solid, fore_colour custom_colour')
print('style', type(style))
writer_sheet.write(int(row_str)-1, int(col_str)-1, reader_cell.value, style)
writer_book.save(self.filePath)
Is there any method to do this? Or, is there any other package to do this?
Thanks a lot.