从Excel单元格中读取数据,并写入另一个在python xlrd / xlwt中应用相同格式的Excel表格

我在python中使用xlrd,xlwt和xlutils库来读写Excel表格。 所以,我已经成功地读写了Excel表格。

但是我需要一些方向来捕获我正在阅读的单元格的格式,并将相同的格式应用于我正在写入的单元格。

以下是我所尝试过的 –

#Open excel sheet & read from tab1 rb = open_workbook(r'C:\Users\abc\excel.xls', formatting_info=True) sheet = rb.sheet_by_name("tab1") #Search the excel sheet for the string and return location of Cell def searchStringCell(searchString): for i in range(sheet.nrows): row = sheet.row_values(i) for j in range(len(row)): if row[j] == searchString: return i,j # Search string to be read header='<Title>' headerTitleX,headerTitleY=searchStringCell(header) cell = sheet.cell(headerTitleX, headerTitleY) print "Title Cell : (",headerTitleX,",",headerTitleY,")" #Write data to cell which is 2 columns to the right of the cell already read wb = copy(rb) w_sheet = wb.get_sheet(0) w_sheet.write(headerTitleX, headerTitleY+2, 'New data') #Have tried the below; not sure about what to do fmt = rb.xf_list[cell.xf_index] bg=fmt.background.pattern_colour_index rgb = wb.colour_map[bg] #Save the changes wb.save(r'C:\Users\abc\excel.xls') 

我试图从表格中读取fmt,bg&rgb; 但我不确定如何应用从中读取数据的相同格式的单元格并将其应用于新单元格。 谢谢。