-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Description
NPOI Version
v2.7.5
File Type
- XLSX
- XLS
- DOCX
- XLSM
- OTHER ->
new XSSFWorkbook();
Upload the Excel File
Please attach your original Excel File to help us reproduce the issue
Reproduce Steps
We have a unit test like this, which creates an empty document:
// Test to verify our method using an empty document.
var workbook = new XSSFWorkbook();
workbook.CreateSheet("Nothing here");
var stream = new MemoryStream();
workbook.Write(stream, leaveOpen: true);
stream.Position = 1;
var result = sut.DoSomething(stream);
// ...Our method does a validation like this:
public bool DoSomething(Stream stream){
if(POIFSFileSystem.HasPOIFSHeader(stream) ||
DocumentFactoryHelper.HasOOXMLHeader(stream)) {
// Good case, return ok
return true;
} else {
// Bad case, return error
return false;
}
}Issue Description
I've updated NPOI from v2.5.6 to v2.7.5 via Nuget.
We have a unit test, to verify our method with an empty document.
As I updated the package (no further changes) our unit-test failed.
I've noticed the following difference:
// Version 2.5.6
POIFSFileSystem.HasPOIFSHeader(input); // => false
DocumentFactoryHelper.HasOOXMLHeader(input); // => true
// Version 2.7.5
POIFSFileSystem.HasPOIFSHeader(input); // => false
DocumentFactoryHelper.HasOOXMLHeader(input); // => falseThese methods are marked as deprecated, so I've updated the code to the following:
if(FileMagicContainer.ValueOf(stream) == FileMagic.OLE2 ||
FileMagicContainer.ValueOf(stream) == FileMagic.OOXML) {
// ...
}The method FileMagicContainer.ValueOf(stream) returns the value UNKNOWN. So the recommended methods are not working, too. The empty document is recognized as "invalid" by our method.
My expectation is, that the code works like before when I update the package or replace the deprecated methods with the mentioned ones. So it seems to be a regression bug.
EDIT: I've tested it locally. 2.7.4 is working fine. So it seems to be a regression from v2.7.4 to `v2.7.5