nissl-lab / npoi

a .NET library that can read/write Office formats without Microsoft Office installed. No COM+, no interop.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Failed to open excel(.xls) with NPOI(2.6.2) with some object not identified

priscilamonteirof opened this issue · comments

NPOI Version

Using 2.6.2

File Type

  • XLSX
  • XLS
  • DOCX
  • XLSM
  • OTHER

Upload the Excel File

Please attach your original Excel File to help us reproduce the issue

Reproduce Steps

When I open a file via stream, I have an error.

See line 5723.
image

Error:
image

Stack Trace:
at NPOI.HSSF.Record.RecordFactory.ReflectionConstructorRecordCreator.Create(RecordInputStream in1)
at NPOI.HSSF.Record.RecordFactory.CreateSingleRecord(RecordInputStream in1)
at NPOI.HSSF.Record.RecordFactoryInputStream.ReadNextRecord()
at NPOI.HSSF.Record.RecordFactoryInputStream.NextRecord()
at NPOI.HSSF.Record.RecordFactory.CreateRecords(Stream in1)
at NPOI.HSSF.UserModel.HSSFWorkbook..ctor(DirectoryNode directory, Boolean preserveNodes)
at NPOI.HSSF.UserModel.HSSFWorkbook..ctor(DirectoryNode directory, POIFSFileSystem fs, Boolean preserveNodes)
at NPOI.HSSF.UserModel.HSSFWorkbook..ctor(POIFSFileSystem fs, Boolean preserveNodes)
at NPOI.HSSF.UserModel.HSSFWorkbook..ctor(Stream s, Boolean preserveNodes)
at NPOI.HSSF.UserModel.HSSFWorkbook..ctor(Stream s)
at Teste.Web.Controllers.SolicitationController.ValidarArquivoXLS_Modelo2(SolicitationViewModel solicitationViewModel ) in C:\Fontes\src\Teste.Web\Controllers\SolicitationController.cs:line 5723

Issue Description

I'm trying to open the excel (workbook), but when I open a file via stream, I have an error.
It is a file generated by third parties that we need to import into our system, so we are not aware of what may be happening nor do we have the possibility of editing it.
I tried deleting the line by line and then opening the file again.
My idea occurs in the first row of the first column, it seems to have a blank image object.
Can you help me?

Why do you use HSSF to open xlsx? It should be XSSF. XSSF namespace is for xlsx and HSSF namespace is for xls.

Sorry, this file is XLS not XLSX.

Can you provide the Excel file to reproduce this issue?

A xls file may have a few possible cases. For example, the file is somewhat broken, or the file is too old (generated by Excel 97 and it's old BIFF format). The easiest way to check what's going on is to resave the file with Microsoft Excel and open it again with NPOI. If NPOI can open it after resaving the file, it means there is something fixed (internal record broken) by Microsoft Excel.

I'm trying to attach it but it's not loading. Is there any other way to send it?

You can send it to my email: tonyqus@gmail.com

I just sent the file by email.

I checked the file. The size of FtCfSubRecord is 0, which is incorrect.

Unhandled exception. NPOI.Util.RecordFormatException: Unable to construct record instance
 ---> NPOI.Util.RecordFormatException: Unexpected size (0)
   at NPOI.HSSF.Record.FtCfSubRecord..ctor(ILittleEndianInput in1, Int32 size) in C:\github\npoi\main\HSSF\Record\FtCfSubRecord.cs:line 63
   at NPOI.HSSF.Record.SubRecord.CreateSubRecord(ILittleEndianInput in1, CommonObjectType cmoOt) in C:\github\npoi\main\HSSF\Record\SubRecord\SubRecord.cs:line 58
   at NPOI.HSSF.Record.ObjRecord..ctor(RecordInputStream in1) in C:\github\npoi\main\HSSF\Record\ObjRecord.cs:line 102

After resaving the file with Microsoft Excel, it can be opened correctly with NPOI. It means Excel fixes some internal records. You need to check with the provider of this Excel.

I did exactly that, opened the file in Excel and saved a copy of it.
As soon as I put it to import, the error appeared: Wrong Local header signature: 0xE011CFD0.
Is there anything else that should be done when saving the file?

at ICSharpCode.SharpZipLib.Zip.ZipInputStream.GetNextEntry()
at NPOI.OpenXml4Net.Util.ZipInputStreamZipEntrySource..ctor(ZipInputStream inp)
at NPOI.OpenXml4Net.OPC.ZipPackage..ctor(Stream in1, PackageAccess access)
at NPOI.OpenXml4Net.OPC.OPCPackage.Open(Stream in1)
at NPOI.Util.PackageHelper.Open(Stream is1)
at NPOI.XSSF.UserModel.XSSFWorkbook..ctor(Stream is1)
at Yamaha.GQC.Web.Controllers.SolicitacoesInspecaoController.ValidarArquivoXLS_Modelo2(RealizarInspecaoViewModel realizarInspecaoViewModel) in C:\Yamaha\Fontes\gqc\src\Yamaha.GQC.Web\Controllers\SolicitacoesInspecaoController.cs:line 5723

The file is with xls extension. You should keep using HSSFWorkbook instead of XSSFWorkbook.

ok, I got it, thanks for the help.

I will contact the owner of the file and see what could be done.