Free Support Forum - aspose.com

Memory stream doesn`t save the whole content

This Memory Stream donot have the whole content it contains only Evalution Warning Sheet when I am taking this stream out and displaying it in browser. I have a limitation that I cannot use Response Object in Excel.Save method. However if I save the objExcel to file on hard disk and open it and assign to stream then it is taking the whole content.

MemoryStream msSave = new MemoryStream();

workbook.Save(msSave, FileFormatType.Excel2003);

byte[] exceldata = msSave.ToArray(); - this is about 6140 bytes. Should be 291840

Then I save the array to a database.

When trying to save it to a file it contains only 1 sheet instead of 6(my file is of 6 sheets)

FileStream fs = new FileStream("d:\\abc.xls", FileMode.Create, FileAccess.ReadWrite);

msSave.WriteTo(fs);

msSave.Close();

fs.Close();

When I use this it works fine

workbook.Save(path, FileFormatType.Default);

saves all the data to file at specified path but donot save it in Memory Stream. I am right now using evaluation version. Please let me know is this a problem with evaluation version or with DLL.

Hi,

Thanks for considering Aspose.

No, there is no such problem with the evaluation version. I tested your scenario and I don't find the problem you have mentioned. Could you create a sample test project, zip and post it here to show the issue, We will check it soon.

Following is my testing code using a template file.

Workbook workbook = new Workbook();
//I use a template excel file.
workbook.Open(@"d:\test\Book1.xls"); //- this is about 1500 bytes in size.
MemoryStream msSave = new MemoryStream();
workbook.Save(msSave, FileFormatType.Excel2003);
byte[] exceldata = msSave.ToArray();

FileStream fs = new FileStream("d:\\test\\mytestbook.xls", FileMode.Create, FileAccess.ReadWrite);
msSave.WriteTo(fs);
msSave.Close();
fs.Close();
//I got the file mytestbook.xls with exactly same bytes.

Thank you.

Thanks and sorry. It was mistake in my code. It`s my fault :slight_smile: