Search code examples
xlwt

write_rich_text of xlwt returns error


I am using xlwt and the following code returns the error Worksheet object has no attribute write_rich_text Why would that be?

seg1 = ("NOT ", Font1)

seg2 = (str(data['Customer'])[:-1], Font2)

sheet1.write_rich_text(row, 4, (seg1, seg2) , Style1)

Note: I am using xlwt 0.7.5 and I see write_rich_text() defined in worksheet.py file


Solution

  • How are you initializing your sheet1 variable?

    Make sure there is a page first:

    wb = xlwt.Workbook()
    sheet1 = wb.add_sheet('Sheet1')
    sheet1.write_rich_text(....)
    

    Also you want to take into consideration that write_rich_text is not included in all versions of xlwt so you might want to make sure that the version of xlwt that you are using is the same version that you verified that actually has write_rich_text. Clearly the version that is imported into your app doesn't know anything about a write_rich_text method.