Merge_cell error opening Excel file created with Python & Openpyxl

479 views
Skip to first unread message

pcsailor

unread,
Oct 13, 2018, 9:32:21 PM10/13/18
to openpyxl-users
Hi,

Has anyone seen this error?  Is happens every time I open up this Excel file I've created with Python & Openpyxl.

Excel-Startup-Error_01a.png


Excel-Startup-Error_01b.png


Excel-Startup-Error_01c.png


Excel-Startup-Error_01d.png


Where is the 'Merge cells error from /xl/worksheets/sheet2.xml part'?  I don't have a 'sheet2' in this spreadsheet.

I can't get on this site from my work PC <http://schemas.openxmlformats.org/spreadsheetml/2006/main> and I'm not seeing other clues.

Thanks,
phil

Charlie Clark

unread,
Oct 14, 2018, 4:38:31 AM10/14/18
to openpyx...@googlegroups.com
Am .10.2018, 03:32 Uhr, schrieb pcsailor <philcu...@gmail.com>:

> Hi,
>
> Has anyone seen this error? Is happens every time I open up this Excel
> file I've created with Python & Openpyxl.

Excel creates these error messages when it encounters invalid bits of XML.
It then generally excludes the relevant package part. The logs aren't
hugely informative but at least this one tells us that the <mergedCells>
element of the worksheet is invalid. You can use a validator such as that
in lxml or the Office OpenXML Productivity Tool to find out exactly what's
invalid. You're using a patch on openpyxl to handle all those merged
ranges so it's probably related to that.

> Where is the 'Merge cells error from /xl/worksheets/sheet2.xml part'? I
> don't have a 'sheet2' in this spreadsheet.

No, but worksheets are always numbered in the archive.

> I can't get on this site from my work PC
> <http://schemas.openxmlformats.org/spreadsheetml/2006/main>
> and I'm not seeing other clues.

It's an XML namespace declaration. I think the idea was originally that
the schemas would be available under the URL but in practice they are just
unique prefixes for the XML elements. This particular namespace from Excel
2007, ie. before the specification became official, and is used throughout
OOXML files.

Charlie
--
Charlie Clark
Managing Director
Clark Consulting & Research
German Office
Kronenstr. 27a
Düsseldorf
D- 40217
Tel: +49-211-600-3657
Mobile: +49-178-782-6226

pcsailor

unread,
Oct 14, 2018, 11:03:04 PM10/14/18
to openpyxl-users
Hi Charlie,

Thank you for the through explanation.  Are you suggesting that my attempt to repair the "error importing multiple worksheets into one Excel file" but commenting out this code is causing the 'Excel file-open error' I'm talking about here?

File location (on my Win10 PC):
C:\Python36x64\Lib\site-packages\openpyxl\reader\worksheet.py (lines 255 & 256)

    def parse_merge(self, element):
        merged = MergeCells.from_tree(element)
        self.ws.merged_cells.ranges = merged.mergeCell
        # for cr in merged.mergeCell:
            # self.ws._clean_merge_range(cr)


Is there a solution with this, for either problem (mutli-page importing with correct formatting and/or opening without a MS-Excel error)?  It seems either way this won't work.  I'm trying to pass this along to 'non-technical' co-workers and have a complete, multi-page spreadsheet that prints perfectly formatted and does this with a double-click from their desktop.

Am I too ambitious here?

Thanks,
phil

pcsailor

unread,
Oct 14, 2018, 11:05:03 PM10/14/18
to openpyxl-users
'by', not 'but' commenting
Reply all
Reply to author
Forward
0 new messages