XMLException when reading the Excel file

Apr 20, 2010 at 4:03 AM
Edited Apr 20, 2010 at 5:01 AM

 My application will  create two worksheets.  and then  my application  read the worksheets.  When reading the worksheets, EPPLUS will throw the XMLException. Not all the Excel files  created by EPPLUS will have the exception.  The exception just occasionally happened. How can I  fix it? THX!!!

The following are the details:

When the application  reads the file using EPPLUS.(ExcelWorksheet ExcelWorksheet_ClassInfo = xlPackage.Workbook.Worksheets["ClassInfo"];)

EPPLUS will throw the XMLException error:   Unexpected end of file has occurred. The following elements are not closed: worksheet. Line 1, position 572.
The StackTrace:
  at System.Xml.XmlTextReaderImpl.Throw(Exception e)
   at System.Xml.XmlTextReaderImpl.Throw(String res, String arg)
   at System.Xml.XmlTextReaderImpl.Throw(Int32 pos, String res, String arg)
   at System.Xml.XmlTextReaderImpl.ThrowUnclosedElements()
   at System.Xml.XmlTextReaderImpl.ParseElementContent()
   at System.Xml.XmlTextReaderImpl.Read()
   at System.Xml.XmlLoader.LoadNode(Boolean skipOverWhitespace)
   at System.Xml.XmlLoader.LoadDocSequence(XmlDocument parentDoc)
   at System.Xml.XmlLoader.Load(XmlDocument doc, XmlReader reader, Boolean preserveWhitespace)
   at System.Xml.XmlDocument.Load(XmlReader reader)
   at System.Xml.XmlDocument.LoadXml(String xml)
   at OfficeOpenXml.ExcelWorksheet.CreateXml()
   at OfficeOpenXml.ExcelWorksheet..ctor(XmlNamespaceManager ns, ExcelPackage excelPackage, String relID, Uri uriWorksheet, String sheetName, Int32 sheetID, Int32 positionID, Boolean hide)
   at OfficeOpenXml.ExcelWorksheets..ctor(ExcelPackage xlPackage)
   at OfficeOpenXml.ExcelWorkbook.get_Worksheets()
   at Upload.UpdateWebwithExcel.Page_Load(Object sender, EventArgs e) in C:\Documents and Settings\manuelkwok\My Documents\Visual Studio 2008\Projects\Upload\Upload\UpdateWebwithExcel.aspx.cs:line 69
   at System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e)
   at System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e)
   at System.Web.UI.Control.OnLoad(EventArgs e)
   at System.Web.UI.Control.LoadRecursive()
   at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

Not all the Excel files created by EPPLUS will have the exception.  The exception just occasionally happened.

Coordinator
Apr 20, 2010 at 6:36 AM

Can you send me the sheet that fails and the code that creates it. Create an issue and upload it

Sep 15, 2010 at 12:05 AM

I´m having the same problem.

I don´t know if it could help, but this is my stack trace:

  • Unexpected end of file has occurred. The following elements are not closed: worksheet. Line 2, position 857.
  • System.Xml.XmlException: Unexpected end of file has occurred. The following elements are not closed: worksheet. Line 2, position 857. at System.Xml.XmlTextReaderImpl.Throw(Exception e) at System.Xml.XmlTextReaderImpl.Throw(String res, String arg) at System.Xml.XmlTextReaderImpl.Throw(Int32 pos, String res, String arg) at System.Xml.XmlTextReaderImpl.ThrowUnclosedElements() at System.Xml.XmlTextReaderImpl.ParseElementContent() at System.Xml.XmlTextReaderImpl.Read() at System.Xml.XmlLoader.LoadNode(Boolean skipOverWhitespace) at System.Xml.XmlLoader.LoadDocSequence(XmlDocument parentDoc) at System.Xml.XmlLoader.Load(XmlDocument doc, XmlReader reader, Boolean preserveWhitespace) at System.Xml.XmlDocument.Load(XmlReader reader) at System.Xml.XmlDocument.LoadXml(String xml) at OfficeOpenXml.ExcelWorksheet.CreateXml() at OfficeOpenXml.ExcelWorksheet..ctor(XmlNamespaceManager ns, ExcelPackage excelPackage, String relID, Uri uriWorksheet, String sheetName, Int32 sheetID, Int32 positionID, Boolean hide) at OfficeOpenXml.ExcelWorksheets..ctor(ExcelPackage xlPackage) at OfficeOpenXml.ExcelWorkbook.get_Worksheets()

 

Coordinator
Sep 15, 2010 at 5:49 PM

Hi,

This problem was supposed to be fixed in version 2.7, so make sure you use this version.

If you do and it still fails, create an issue and upload the template so I can have a look at it.

Jan

Sep 15, 2010 at 6:00 PM

Ok! I was using a previous version (2.6).

This component is great!

Thanx!