XlsxWriter error for percent format

Gabriel picture Gabriel · Oct 6, 2015 · Viewed 7.5k times · Source

I'm using Pandas and exporting data to excel using XlsxWriter. One of the data columns has floats and needs to be formatted as percent, so this is how I do it:

percent_fmt = workbook.add_format({'num_format': '0.00%'})
worksheet.set_column('E:E', percent_fmt)

After that the following error appears:

File "C:\Program Files\Anaconda\lib\site-packages\xlsxwriter\worksheet.py", line 4688, in _write_col_info / float(max_digit_width) * 256.0) / 256.0

TypeError: unsupported operand type(s) for *: 'Format' and 'int'

What am I doing wrong here?

Answer

jmcnamara picture jmcnamara · Oct 6, 2015

You need to specify a width before the format or None if you don't want to adjust the width.

worksheet.set_column('E:E', None, percent_fmt)