Cannot open xlsx with comments generated by LibreOffice

Jun 26, 2014 at 12:10 PM
Hello,

I'm experiencing an odd issue with ClosedXML: I cannot open an xlsx workbook if it contains comments on any cell AND has been saved by LibreOffice.
Comments saved by Microsoft Excel are fine, but if I take the same file, save it again (even without modifications) with LibreOffice, then the workbook cannot be opened anymore. Removing the comment with LibreOffice solves the issue.

It fails at the following line:
XLWorkbook workbook = new XLWorkbook(m_excelPath);

The error I get is the following:
'type' is a duplicate attribute name. Line 1, position 525.
at System.Xml.XmlTextReaderImpl.Throw(Exception e)
at System.Xml.XmlTextReaderImpl.AttributeDuplCheck()
at System.Xml.XmlTextReaderImpl.ParseAttributes()
at System.Xml.XmlTextReaderImpl.ParseElement()
at System.Xml.XmlTextReaderImpl.ParseElementContent()
at System.Xml.XmlTextReaderImpl.Read()
at System.Xml.Linq.XContainer.ReadContentFrom(XmlReader r)
at System.Xml.Linq.XContainer.ReadContentFrom(XmlReader r, LoadOptions o)
at System.Xml.Linq.XDocument.Load(XmlReader reader, LoadOptions options)
at System.Xml.Linq.XDocument.Load(XmlReader reader)
at ClosedXML.Excel.XDocumentExtensions.Load(Stream stream)
at ClosedXML.Excel.XLWorkbook.LoadSpreadsheetDocument(SpreadsheetDocument dSpreadsheet)
at ClosedXML.Excel.XLWorkbook.LoadSheets(String fileName)
at ClosedXML.Excel.XLWorkbook.Load(String file)
at ClosedXML.Excel.XLWorkbook..ctor(String file, XLEventTracking eventTracking)
at ClosedXML.Excel.XLWorkbook..ctor(String file)


Right now we decided not to use comments, but it would be great if this could work as well.

Thanks in advance,

Martin
Coordinator
Jul 9, 2014 at 4:39 PM
Attach a file that doesn't open.
Sep 1, 2014 at 3:09 PM
Hello,

Apologies for the late answer.

I could reproduce a similar error with the following file: http://speedy.sh/T84cG/ClosedXML-CommentIssue.xlsx
As described in the original post, this file cannot be opened as long as there's a comment in the A2 cell. By deleting the comment, the file opens again.

The error occurs at the same line (XLWorkbook constructor), however the error details are slightly different (I'm not sure why, but the basic problem remains the same - the file can't be opened):
System.InvalidOperationException: Sequence contains no matching element
   at System.Linq.Enumerable.First[TSource](IEnumerable`1 source, Func`2 predicate)
   at ClosedXML.Excel.XLWorkbook.LoadSpreadsheetDocument(SpreadsheetDocument dSpreadsheet)
   at ClosedXML.Excel.XLWorkbook.LoadSheets(String fileName)
   at ClosedXML.Excel.XLWorkbook.Load(String file)
   at ClosedXML.Excel.XLWorkbook..ctor(String file, XLEventTracking eventTracking)
   at ClosedXML.Excel.XLWorkbook..ctor(String file)
Thanks in advance,
Martin