英文:
xlsxwriter set num_format = "0!.0," but when i open it by excel, the format show is 0!!.0,
问题
Here's the translated code portion without the translation of the code itself:
import xlsxwriter
wb = xlsxwriter.Workbook('hello.xlsx')
ws = wb.add_worksheet()
ws.set_column('B:B', 30)
num = 1234.52
num_formats = (
'0.00',
'#,##0.00',
'0.00E+00',
'##0.0E+0',
'₹#,##0.00',
'0!.0,'
)
ws.write('A1', 'Formatted Number')
ws.write('B1', 'Format')
row = 1
for fmt in num_formats:
format = wb.add_format({'num_format': fmt})
ws.write_number(row, 0, num, format)
ws.write_string(row, 1, fmt)
row += 1
wb.close()
Regarding the issue with the Excel format, it appears that the num_format
has been set to '0!!.0'
as you mentioned. If you want to correct this issue, you may need to adjust the num_formats
tuple to use a different number format that suits your needs.
英文:
import xlsxwriter
wb = xlsxwriter.Workbook('hello.xlsx')
ws = wb.add_worksheet()
ws.set_column('B:B', 30)
num=1234.52
num_formats = (
'0.00',
'#,##0.00',
'0.00E+00',
'##0.0E+0',
'₹#,##0.00',
'0!.0,'
)
ws.write('A1', 'Formatted Number')
ws.write('B1', 'Format')
row = 1
for fmt in num_formats:
format = wb.add_format({'num_format': fmt})
ws.write_number(row, 0, num, format)
ws.write_string(row, 1, fmt)
row += 1
wb.close()
But when I open this excel by office, the format is wrong, like this:
The num_format has been set to 0!!.0
,
答案1
得分: 2
When I run your sample code I get the expected result:
However, when I resave the file with Excel and look at the internal contents I see that it is storing the format as "0!.0,"
. So maybe try that instead.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论