Xlsx broken after Open & Save via Stream

I am using the following Code with Aspose.Cells 17.12.0 .NET

using (Workbook tmpExcelWorkbook = new Workbook(inDocument)) { var tmpSaveFileFormat = (SaveFormat) tmpExcelWorkbook.FileFormat; tmpExcelWorkbook.Save(inDocument, tmpSaveFileFormat); }
On a mostly empty file (only text in a few cells).

After using the above code and saving the stream back to the disk. The resulting Excel is broken, but can be repaired by Excel 2013 and shows the correct data afterwards.

When looking into the sheetdata, there is the attribute dyDescent replaces with ht after saving with Aspose.Cells.

A demo file I used and the result:
BeforeAndAfterSave.zip (17.3 KB)

@newwin-sws,

Please try our latest version/fix: Aspose.Cells for .NET v17.12.3:

I have tested your scenario/case using the following sample code with your template file using v17.12.3, it works fine and the output file (attached) is fine tuned:
e.g
Sample code:

using (Workbook tmpExcelWorkbook = new Workbook("e:\\test2\\ErrorTest.xlsx")) { var tmpSaveFileFormat = (SaveFormat)tmpExcelWorkbook.FileFormat; tmpExcelWorkbook.Save("e:\\test2\\ErrorTest1.xlsx", tmpSaveFileFormat); }

If you still find the issue with v17.12.3, kindly either provide a simple console demo application (you may zip the project prior attaching it here (excluding Aspose.Cells assembly)) or paste the runnable sample code here, we will check it soon.
file1.zip (6.8 KB)

I found out what the reason for this behaviour is:
If you call Save(Stream) with a non-empty Stream, all the data is appended.
Excel 2013 is able to extract the second data from the file and therefore can fix it (Excel 2016 can’t).

A solution to help other with this problem could be that Aspose.Cells checks if the incomming stream has Position==0. And if not, throw an exception/warning, Because the resulting file in the stream will never be a valid one.

Thank you for your help

@newwin-sws,

Good to know that you are able to sort out your issue now. You may also specify the position to 0 in the stream after you save the workbook to stream, see the following code segments for your reference:
e.g
Sample code:


MemoryStream ms = new MemoryStream();
workbook.Save(ms, Aspose.Cells.SaveFormat.Xlsx);
ms.Position = 0;


MemoryStream ms = new MemoryStream();
workbook.Save(ms, SaveFormat.Xlsx);
ms.Seek(0, SeekOrigin.Begin);

Hope, this helps a bit.