[已解决]NPOI Wrong Local header signature: 0x0;Your InputStream was neither an OLE2 stream, nor an OOXM

问题描述:

1.xlsx文件 用new XSSFWorkbook(stream);报错Wrong Local header signature: 0x0;

2.xlsx文件WorkbookFactory.Create(stream)报错Your InputStream was neither an OLE2 stream, nor an OOXM

问题原因:

多次读文件至stream 而stream.Position未恢复。

var stream = file.InputStream;
var buffer = new byte[stream.Length];
stream.Read(buffer, 0, buffer.Length);
stream.Position = 0;

你可能感兴趣的:(C#)