[英]xlsxwriter is creating a corrupted file
I'm using this code to test xlswriter functionnalitues. 我正在使用此代码来测试xlswriter functionnalitues。
import xlsxwriter
# -*- coding: utf-8-sig-*-
workbook = xlsxwriter.Workbook("filename.xlsx")
worksheet = workbook.add_worksheet()
worksheet.add_table(0,0, 1, 11,{'columns': [{'header': 'ID'},
{'header': '1'},
{'header': u'ééé'},
{'header': 'M'},
{'header': 'C'},
{'header': 'P'},
{'header': u'o'},
{'header': 'Pe'},
{'header': 'F'},
{'header': u'l'},
{'header': 'C'},
{'header': 'f'}
]})
workbook.close()
Excel is complaining about the file being corrputed. Excel抱怨文件已被纠正。 If I accept the repair I got the content as expected. 如果我接受维修,则可以得到预期的内容。
Update: I have the same problem with this minimalistic code: 更新:这个简约代码存在相同的问题:
import xlsxwriter
workbook = xlsxwriter.Workbook("filename.xlsx")
worksheet = workbook.add_worksheet("hi")
worksheet.add_table(0,0, 1, 2,{'columns': [{'header': 'ID'},
{'header': '1'},
{'header': '1'}]})
workbook.close()
The issue in the second example is that Excel doesn't allow you to have two table headers with the same case-insensitive value ("1" in this case). 第二个示例中的问题是Excel不允许您使用具有不区分大小写的值(在这种情况下为“ 1”)的两个表头。 The following works: 以下作品:
import xlsxwriter
workbook = xlsxwriter.Workbook("filename.xlsx")
worksheet = workbook.add_worksheet("hi")
worksheet.add_table(0, 0, 1, 2,{'columns': [{'header': 'ID'},
{'header': '1'},
{'header': '2'}]})
workbook.close()
There should be a warning from XlsxWriter about this but I wasn't aware of it until now. XlsxWriter应该对此发出警告,但直到现在我才意识到。 I'll add a check in an upcoming release. 我将在即将发布的版本中添加一张支票。 (Tracked on Github as issue #362 .) (在Github上作为问题#362进行了跟踪。)
This also looks like the issue in the first example since you have two headings called 'C'
and 'F'
/ 'f'
- Excel requires header names to be case insensitively unique. 这也看起来像第一个示例中的问题,因为您有两个名为'C'
和'F'
/ 'f'
标题-Excel要求标头名称区分大小写,不区分大小写。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.