wordpress hit counter
Re: getting error "File contains corrupted data" when trying to open excel file using OpenXML - .Net - Development Tools - OpenXML Developer

Re: getting error "File contains corrupted data" when trying to open excel file using OpenXML

Development Tools

Discussions about working with Open XML using a wide range of development tools

getting error "File contains corrupted data" when trying to open excel file using OpenXML

  • rated by 0 users
  • This post has 1 Reply |
  • 2 Followers
  • Hi,
    i am having application developed in .Net 2.0 and using OpenXML to import excel file into aplication but getting following exception on this line of code

    SpreadsheetDocument myWorkbook = SpreadsheetDocument.Open(Path, true);

    Can anybody please help me on this as this is bvery much urgent for me.
    Following are exception details

    --------------------------------- Error message -------

    System.IO.FileFormatException: File contains corrupted data.
    at MS.Internal.IO.Zip.ZipIOEndOfCentralDirectoryBlock.FindPosition(Stream archiveStream)
    at MS.Internal.IO.Zip.ZipIOEndOfCentralDirectoryBlock.SeekableLoad(ZipIOBlockManager blockManager)
    at MS.Internal.IO.Zip.ZipIOBlockManager.LoadEndOfCentralDirectoryBlock()
    at MS.Internal.IO.Zip.ZipArchive..ctor(Stream archiveStream, FileMode mode, FileAccess access, Boolean streaming, Boolean ownStream)
    at MS.Internal.IO.Zip.ZipArchive.OpenOnFile(String path, FileMode mode, FileAccess access, FileShare share, Boolean streaming)
    at System.IO.Packaging.ZipPackage..ctor(String path, FileMode mode, FileAccess access, FileShare share, Boolean streaming)
    at System.IO.Packaging.Package.Open(String path, FileMode packageMode, FileAccess packageAccess, FileShare packageShare, Boolean streaming)
    at System.IO.Packaging.Package.Open(String path, FileMode packageMode, FileAccess packageAccess, FileShare packageShare)
    at DocumentFormat.OpenXml.Packaging.OpenXmlPackage.OpenCore(String path, Boolean readWriteMode)
    at DocumentFormat.OpenXml.Packaging.SpreadsheetDocument.Open(String path, Boolean isEditable, OpenSettings openSettings)
    at DocumentFormat.OpenXml.Packaging.SpreadsheetDocument.Open(String path, Boolean isEditable)
    at Banking_ImportStatements.ImportOnlineTemplate(String name, Int64 len) in e:\Projects\Siondo ERP\2 Siondo ERP EXECUTION\3 Source Code\SiondoERP\SiondoERPUI\Banking\ImportStatements.aspx.cs:line 1121}

    Thanks & Regards,
    Vikas Jaigude.
  • Hi Vikas

    Are you sure the xlsx file is in correct OpenXML format?

    A simple test is to open it in Office.  Next is to validate it using the OpenXML SDK v2.0 Productivity Tool.

    To me this looks like the xlsx is not in a valid zip state..  Could you please try renaming the .xlsx file's extension to .zip and then extract this?
Page 1 of 1 (2 items)