Reading UTF8 MemoryStream Fails

I have a byte array of data in a MemoryStream and I’m trying to get Aspose.Cells to read it, but it keeps failing, even though with this same file a regular FileStream will work. I’ve attached the spreadsheet I’m using. The error that’s bubbling up is:


Cannot read that as a ZipFile
----> . : Bad signature (0xBDBFEFBD) at position 0x00001F1C

Code:

var data = File.OpenRead(“D:\temp\importtemp\1.import.xlsx”);

var sr = new StreamReader(data);
var encoding = new UTF8Encoding();
var bytes = encoding.GetBytes(sr.ReadToEnd());

var stream = new MemoryStream(bytes);
var worksheet = new Workbook(stream);

Hi,


I use the following code and it works fine streaming your template XLSX file by Aspose.Cells for .NET.

Sample code:
FileStream stream = File.OpenRead(“e:\test2\1.import.xlsx”);
byte[] buffer = new byte[stream.Length];
stream.Read(buffer, 0, buffer.Length);

Workbook workbook = new Workbook(stream);

I think you’re not understanding the real issue. Maybe I didn’t explain it well enough.


I have a byte array of data stored in the DB. For the purposes of this example I was using a FileStream to open a file and then convert it to a MemoryStream to mimic what we’d have in production: a byte array with out a FileStream.

That byte array of data needs to be converted to a MemoryStream, which Aspose.Cells should accept. However, it doesn’t work.

If you use my example, you’ll see that it doesn’t. Please explain if I’m doing something wrong here or if there’s a bug in Aspose.Cells that doesn’t handle MemoryStreams correctly.

Hi,

Please convert your UTF8 bytes into Unicode bytes, then it will work fine.

e.g


//Provide memory stream unicode bytes instead of utf8 bytes

var stream = new MemoryStream(uniBytes);

stream.Position = 0;


var workbook = new Workbook(stream);