1

So here's the code:

            using (FileStream file = new FileStream(databaseLocation, FileMode.Open, FileAccess.Read))
        {
            // _Sheet is of type IWorksheet
            _Sheet = new XSSFWorkbook(file).GetSheetAt(0);
        }

This, continuously and regardless of what overload I use, throws a variety of exceptions. I've chosen the particular overload above for this question because everybody else seems to be able to open Excel 2007 (.xlsx) files with (basically) this exact method!

This particular overload provides me with the error "ZipException - EOF in header". Another lovingly descriptive error "ZipException - Cannot find central dictionary" is given for the string overload (i.e. _Sheet = new XSSFWorkbook(databaseLocation).GetSheetAt(0);).

I don't know if it's an issue with the way that NPOI implements the ICSharpCode's SharpZipLib. Either way, I need to be able to open Excel 2007 files.

I have tried resetting file.Position to 0, amongst other things suggested on a Google search, but there isn't much to go off of. Help me before I rip my hair out!

Nick Bull
  • 9,518
  • 6
  • 36
  • 58
  • 1
    You have verified that the file in question is in fact a legal .xlsx file? Have you tried renaming it to .zip and opening it up in any zip-manager software, to ensure it's not an older .xls file with an incorrect extension? – Lasse V. Karlsen Jan 07 '14 at 14:57
  • This was freshly created from Microsoft Excel itself, and saved as a .xlsx file, so I could not guarantee more that it is a valid .xlsx file unfortunately! I will recreate the file, retest and report back if this makes a difference. – Nick Bull Jan 07 '14 at 15:12
  • Thank you @LasseV.Karlsen, for whatever reason, Excel is saving any blank workbook as ".xlsx" in extension with a file size of 0KB, unless I save the workbook as non-blank, delete whatever I have inputted, and resave it as a blank workbook, in which case it has a filesize of 8.41KB. No idea why that is, but the question is solved. Thank you :) – Nick Bull Jan 07 '14 at 15:21
  • Which version of NPOI are you using? – Tony Qu May 20 '14 at 04:10

0 Answers0