我想将我的excel表中的数字格式从1000,12
调整为欧洲风格(带千位分隔符):1.000,12
和python。
在excel中,格式设置为:#.##0,00
[当我想在我的工作簿中将其与xlsxwriter
一起使用(展平为数据框表):
import xlsxwriter
workbook = xlsxwriter.Workbook('excel.xlsx', options={'nan_inf_to_errors': True})
worksheet1 = workbook.add_worksheet('table1')
numbersformat = workbook.add_format({'num_format': '#.##0,00'})
worksheet1.add_table(3, 1, flattened.shape[0]+3, flattened.shape[1],
{'data': flattened.values.tolist(),
'columns': [{'header': c} for c in flattened.columns.tolist()],
'style': 'Table Style Medium 9',
'format': numbersformat})
我得到一个空的数据框。导致表结果的地方:
worksheet1.add_table(3, 1, flattened.shape[0]+3, flattened.shape[1],
{'data': flattened.values.tolist(),
'columns': [{'header': c} for c in flattened.columns.tolist()],
'style': 'Table Style Medium 9',})
我的数据框flattened
看起来像这样:
Department Name Month:1 Month:2 Month:All
Bistro Ama 82.75 82.75
Bistro Beb 100.00 212.00 312.00
All 182.75 212.00 394.75
我想将我的excel表中的数字格式从1000,12调整为欧洲风格(带有千位分隔符):1.000,12(使用python。
在excel中,格式设置为:
#.##0,00
这里的问题是,即使格式显示为#.##0,00
,它实际上也被Excel存储为#,##0.00
(即美国语言环境)。您的操作系统可能默认使用千位分隔符“。”。和“”的小数点分隔符,并且Excel在读取并显示值时将#,##0.00
更改为#.##0,00
。
如果您将代码更改为具有美式风格的格式,您的程序将按预期运行:
numbersformat = workbook.add_format({'num_format': '#,##0.00'})