简体   繁体   English

如何使用xlsxwriter模块在xlsx中放入千位分隔符?

[英]How to put in the thousands separator in xlsx using xlsxwriter module?

When using xlsxwriter how do you get the xlsx file to contain columns with comma formatted numbers(not strings) in a column? 当使用xlsxwriter时,如何让xlsx文件包含列中带逗号格式的数字(而不是字符串)的列?

What I want to do - turn 1000 into 1,000 while preserving value as a number 我想做什么 -将1000变为1,000,同时保留价值作为数字

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 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM