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

在使用xlsxwriter时,如何让xlsx文件在列中包含使用逗号格式化数字(而不是string)的列?

我想做什么 –将1000变成1000,同时保留价值作为一个数字

尝试失败…

#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) 

您需要设置单元格的格式来指定应该如何表示数字:

 num_fmt = workbook.add_format({'num_format': '#,###'}) ... sheet.write_number(0, 0, 1000, num_fmt)