File getting corrupted when saving in memory stream

I am using Aspose 8.6.3

I have noticed when saving to a memory stream then saving the file to XLS or XLSX,
File is getting corrupted.

MemoryStream ms = new MemoryStream();
wrk.Save(ms, SaveFormat.Auto);
result.Result = ms.GetBuffer();

Then I tried adding this and was able to generate uncorrupted XLSX.
XLS is still corrupted
ms.Capacity = Convert.ToInt32(ms.Length);

To be able to save XLS, I need to use SaveFormat.Excel97to2003

Hi,

Thanks for your posting and using Aspose.Cells.

Please change your code into this and see if it works.

C#

MemoryStream ms = new MemoryStream();
ms.Position = 0;
wrk.Save(ms, SaveFormat.Auto);
result.Result = ms.GetBuffer();

This is the error for XLSX, when about to open…

Excel found unreadable content in xx.xlsx. Do you want to recover the contents of this workbook.

When opened this is the message : Excel completed file level validation and repair. Some parts of this workbook may have been repaired or discarded.



This is the error for XLS, when about to open…
The file you are tring to open, xx.xls, is in a different format than specified by file extension. Verify that the file is not corrupted and is from a trusted source before opening the file.

When opened, is is corrupted.

Hi,

Thanks for your feedback and using Aspose.Cells.

Please download and try the latest version:

        <a href="https://forum.aspose.com/t/36555">Aspose.Cells
            for .NET v8.6.3.5</a>
         and see if it makes any difference and resolves your issue.<br><br>If your issue still occurs, then please check if it occurs every type of excel file. Please try the excel file attached by me with this post.<br><br>Lastly provide me your sample console application replicating this issue along with your source excel files used in your code for our testing. We will look into it and update you asap.<br><br>Please also try this code. Use <b>MemoryStream.ToArray()</b> method instead of <b>MemoryStream.GetBuffer()</b> method. It should fix your issue.<br><br><b>C#</b><br><div class="csharpcode"><font color="#800080">Workbook wrk = new Workbook("sample.xls");<br><br>MemoryStream ms = new MemoryStream();<br>wrk.Save(ms, SaveFormat.Auto);<br>byte[] result = ms.ToArray();<br><br>File.WriteAllBytes("test.xlsx", result);</font><br></div><br>

It had fixed for XLSX format but not XLS.

I’ll probably try to do the workaround to use SaveFormat.Excel97To2003 for XLS.

Some of my issues I have logged in the forum seems been fixed by 8.6.3.5.
I am still testing to confirm. Do you have the details for this new version and when it will be released?

Hi,

Thanks for your valuable feedback and using Aspose.Cells.

This is actually a minor release which we share with users via forum. The upcoming major official release will be 8.7.0 which is expected to be released in this week or next week.

However, if you want to use offical version, then you can use the current version i.e
Aspose.Cells for .NET (Latest Version) .

Please feel free to share your test application and your examples excel files so that we fix this bug in our coming releases. Thanks for your cooperation.