I need to style specific cells and rows in the xls file that I create in my program, but I have a few problems, possible misconceptions about how xlwt easyxf works.
Firstly, if I write to a cell without a value and only in style, is the value deleted inside inside?
Secondly, I try to write to cells using the style and value of the cell, but I keep getting the error:
"TypeError: 'XFStyle' object is not callable". -Solved
Now the problem is that styles are not implemented. After writing the cells and outputting it to the xls file, there were no changes in color, bg, size and font.
I tried using this on Google and stuck with other examples, but for some reason my code is not working. There he is:
def stylize_spreadsheet_accordingly(iFile, workbook, row_grey, row_underline, row_font_size, cells_yellow):
print "styling the document..."
new_sheet.col(0).width = 256 * 18
new_sheet.col(1).width = 256 * 69.43
new_sheet.col(2).width = 256 * 9
new_sheet.col(3).width = 256 * 20.71
new_sheet.col(4).width = 256 * 8.43
font_size_style = xlwt.easyxf('font: name Calibri, bold on, height 280;')
font_underline_style = xlwt.easyxf('font: underline on;')
fill_grey_style = xlwt.easyxf('pattern: back_color gray25;')
fill_yellow_style = xlwt.easyxf('pattern: back_color yellow;')
iBook = open_workbook(iFile)
iSheet = iBook.sheet_by_index(0)
for row_index in range(iSheet.nrows):
if row_index in row_grey:
for col_index in range(iSheet.ncols):
new_sheet.write(row_index,col_index, iSheet.cell(row_index,col_index).value, fill_grey_style)
if row_index in row_underline:
for col_index in range(iSheet.ncols):
new_sheet.write(row_index,col_index, iSheet.cell(row_index,col_index).value, font_underline_style)
if row_index in row_font_size:
for col_index in range(iSheet.ncols):
new_sheet.write(row_index,col_index, iSheet.cell(row_index,col_index).value, font_size_style)
for each in cells_yellow:
new_sheet.write(each[0], each[1], iSheet.cell(each[0],each[1]).value, fill_yellow_style)
return workbook
new_sheet - , , , xlwt. , , - , new_sheet. , , , .
P.S. , -, , . .
, , , , , TypeError , , , . xls - . ?