Question

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) 
Was it helpful?

Solution

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)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top