When using xlsxwriter how do you get the xlsx file to contain columns with comma formatted numbers(not strings) in a column?
What I want to do - turn 1000 into 1,000 while preserving value as a number
Failed attempts...
#gives warning in cell (asking if it should be a number) + writes as string not number
sheet.write_string(0,0,re.sub("^0*|\.?0*$","",format(val, ',.10f')) )
# writes as number with no warning, but no commas
sheet.write_number(0,0,1000)
You need to set the cell's format to specify how the number should be represented:
num_fmt = workbook.add_format({'num_format': '#,###'})
...
sheet.write_number(0, 0, 1000, num_fmt)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With