Skip to content

WorkbookFactory.Create(Stream inputStream, string password) returns InvalidFormatException #1662

@plpolak

Description

@plpolak

NPOI Version 2.7.5

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 opening an OOXML using WorkbookFactory.Create(Stream inputStream, string password), the library raises an InvalidFormatException.

This is workign fine in version 2.7.4

Issue Description

The refactoring of the method, is no longer including creating an instance of a PushbackStream before reading the file header. I think this needs to be inserted at line 128 to restore the old behaviour:

        public static IWorkbook Create(Stream inputStream, string password)
        {
            if (inputStream.Length == 0)
                throw new EmptyFileException();

            // INSERT THIS LINE:
            inputStream = new PushbackStream(inputStream);

            FileMagic fm = FileMagicContainer.ValueOf(inputStream);
            switch (fm)
            {

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions