xlsxwriter设置num_format = “0!.0,”,但当我在Excel中打开它时,格式显示为0!!.0。

huangapple go评论74阅读模式
英文:

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:

xlsxwriter设置num_format = “0!.0,”,但当我在Excel中打开它时,格式显示为0!!.0。

The num_format has been set to 0!!.0,

答案1

得分: 2

When I run your sample code I get the expected result:

xlsxwriter设置num_format = “0!.0,”,但当我在Excel中打开它时,格式显示为0!!.0。

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.

英文:

When I run your sample code I get the expected result:

xlsxwriter设置num_format = “0!.0,”,但当我在Excel中打开它时,格式显示为0!!.0。

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.

huangapple
  • 本文由 发表于 2023年5月10日 16:05:07
  • 转载请务必保留本文链接:https://go.coder-hub.com/76216187.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定