Quantcast
Channel: npoi Discussions Rss Feed
Viewing all articles
Browse latest Browse all 637

New Post: EOF In Header exception when reading .xlsm

$
0
0
FYI :

this code works in order to read a file into a XSSFWorkbook:

private IWorkbook InitializeAddingWorkbook(HttpPostedFile postedFile)
 {
    Stream fileStream = postedFile.InputStream;

    byte[] fileContents = new byte[postedFile.ContentLength];
    fileStream.Read(fileContents, 0, postedFile.ContentLength);
    fileStream.Position = 0; // <---- remember to rewind the stream

    return new XSSFWorkbook(fileStream);

}
Just remember that XSSFWorkbook needs a zip library to decode zipped xml, and the stream passed to the unzipper needs to be at 0 position.
When fileStream.Read( ) reads, the stream keeps positioned at end, so when unzipper needs to read it gets "EOF".

Thanks for your help.

Luis.

Viewing all articles
Browse latest Browse all 637

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>