errors when writing more than 52 columns
Created originally on Bitbucket by Anonymous
If you add more than 52 columns; e.g. like this:
#!python
import openpyxl
wb = openpyxl.Workbook( encoding = 'windows-1252' )
ws = wb.get_active_sheet()
ws.title = 'Details'
for row in range(0,1):
for col in range(0,52):
ws.cell(row=row, column=col).value = "hello"
wb.save('test.xlsx')
then Excel 2010 can't read the file - it says the file is corrupted and when it tries to repair the file, there are columns missing.
Having a quick look it seems there are the following problems with the generated xlsx:
• Cells must be in sequential order (based on this code sample: http://msdn.microsoft.com/en-us/library/office/cc861607.aspx), e.g. we can’t have something like this:
#!xml
<c r="AA1" t="s">
<v>0</v>
</c>
<c r="BA1" t="s">
<v>0</v>
</c>
• incorrect usage of a namespace in core.xml. These two lines:
<ns1:created ns2:type=”dcterms:W3CDTF” xmlns:ns1=”http://purl.org/dc/terms/” xmlns:ns2=”http://www.w3.org/2001/XMLSchema-instance”>2014-01-07T20:02:08Z</ns1:created> <ns1:modified ns2:type=” dcterms:W3CDTF” xmlns:ns1=”http://purl.org/dc/terms/” xmlns:ns2=”http://www.w3.org/2001/XMLSchema-instance”>2014-01-07T20:02:08Z</ns1:modified>
Should be:
#!xml
<ns1:created ns2:type=”ns1:W3CDTF” xmlns:ns1=”http://purl.org/dc/terms/” xmlns:ns2=”http://www.w3.org/2001/XMLSchema-instance”>2014-01-07T20:02:08Z</ns1:created>
<ns1:modified ns2:type=”ns1:W3CDTF” xmlns:ns1=”http://purl.org/dc/terms/” xmlns:ns2=”http://www.w3.org/2001/XMLSchema-instance”>2014-01-07T20:02:08Z</ns1:modified>
• [Content_Types].xml should use default namespace. The Microsoft validation tool crashes because of this. That said, Excel is fine with it so correcting this is not a necessity.
Have tried version 1.8, 1.9, and latest of openpyxl.