문제

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)
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top