Hi Maxim,
This is an usage level issue. In the given code snippet we can see that you are using the same stream to read and write the excel file, so the already opened stream has been overwritten which leads to corruption. (i.e) InputStream object is used to load the excel file and the stream is used for saving the excel file.
In order to resolve the issue , clear the stream before saving using SetLength() method. Below we have shared the code snippet to resolve this.
Code snippet :
stream.Position = 0;
IWorkbook workbook = application.Workbooks.Open(stream);
stream.SetLength(0);
workbook.SaveAs(stream); |
Please let us know if this helpful.
Regards,
Karthikeyan