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

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

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:

  1. import xlsxwriter
  2. wb = xlsxwriter.Workbook('hello.xlsx')
  3. ws = wb.add_worksheet()
  4. ws.set_column('B:B', 30)
  5. num = 1234.52
  6. num_formats = (
  7. '0.00',
  8. '#,##0.00',
  9. '0.00E+00',
  10. '##0.0E+0',
  11. '₹#,##0.00',
  12. '0!.0,'
  13. )
  14. ws.write('A1', 'Formatted Number')
  15. ws.write('B1', 'Format')
  16. row = 1
  17. for fmt in num_formats:
  18. format = wb.add_format({'num_format': fmt})
  19. ws.write_number(row, 0, num, format)
  20. ws.write_string(row, 1, fmt)
  21. row += 1
  22. 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.

英文:
  1. import xlsxwriter
  2. wb = xlsxwriter.Workbook('hello.xlsx')
  3. ws = wb.add_worksheet()
  4. ws.set_column('B:B', 30)
  5. num=1234.52
  6. num_formats = (
  7. '0.00',
  8. '#,##0.00',
  9. '0.00E+00',
  10. '##0.0E+0',
  11. '₹#,##0.00',
  12. '0!.0,'
  13. )
  14. ws.write('A1', 'Formatted Number')
  15. ws.write('B1', 'Format')
  16. row = 1
  17. for fmt in num_formats:
  18. format = wb.add_format({'num_format': fmt})
  19. ws.write_number(row, 0, num, format)
  20. ws.write_string(row, 1, fmt)
  21. row += 1
  22. 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:

确定