Error saving an Excel object to a stream multiple times


#1

Hi,

In my application, I save an Excel object to a stream using the following code:

Stream stream = new MemoryStream();
excel.Save(stream, ReportConstants.EXCEL_FORMAT);

At first, I was doing this in two different places in my code - firstly to attach the file to an email, secondly to display the size of the file on a web page. However, the second time that I saved the Excel object, the stream's lenth was 4096 bytes instead of 6411 bytes (or something similar). I didn't test opening the file this second time, so I don't know if any corruption also occurred.

I got around this issue by only saving to a stream once. However, is there an issue with the way I was trying to save or is there a possible bug with this?


#2

When you call Excel.Save method, data in this Excel object is reset. That’s by design. So I think the second file you saved is a blank file.


#3

Thank you, I understand now.

Shandos