Invalid header signature; read 0x2020202020202020, expected 0xE11AB1A1E011CFD0

Mar 11, 2013 at 1:11 PM
I have created a excel file using File.WriteAllText(path, strhtml). as it had direct html table. I dont know if there is a way to create a excel file using html with NPOI. once the file is created i have to add an image to another sheet in the file.
I am opeing the excel file using this code.
Dim file As New FileStream(Server.MapPath("~") & "ExternalPerformanceTrend2.xls", FileMode.Open, FileAccess.Read)
but when i pass file to HSSFWorkbook then it gives this error.
hssfworkbook = New HSSFWorkbook(file)

Invalid header signature; read 0x2020202020202020, expected 0xE11AB1A1E011CFD0
Coordinator
Mar 12, 2013 at 8:47 PM
NPOI is created to create BINARY xls file and OOXML xlsx files. Html is not a supported option in NPOI because Html is plain text, you can totally use StreamWriter to finish the creation of Html.
Mar 7, 2014 at 5:08 PM
Edited Mar 7, 2014 at 5:46 PM
I do not believe his issue has anything to do with HTML. The error comes from trying to create a new workbook using a FileStream. Here is my code:
        Dim Output As New FileInfo(Me.TemporaryPath & FileName & ".xlsx")
        
        Using MyStream As New FileStream(Output.FullName, FileMode.Create)
            Dim MyWorkbook As New HSSFWorkbook(MyStream)
        End Using
The code above fails on the "New HSSFWorkbook" call. If I remove the stream as a parameter to this call it works fine. Here is the error I receive:

Invalid header signature; read 0x0000000000000000, expected 0xE11AB1A1E011CFD0

UPDATE: The following code works using a memory stream indirectly:
        Dim Output As New FileInfo(Me.TemporaryPath & FileName & ".xlsx")
        Dim MyWorkbook As New HSSFWorkbook()

        Using MyStream As New FileStream(Output.FullName, FileMode.Create)
            Using MyMemory As New MemoryStream()
                MyWorkbook.Write(MyMemory)
                MyMemory.WriteTo(MyStream)
            End Using
        End Using