Inconsistency in handling of streams between Words and Cells

Is there a reason why Aspose.Cells disposes the source stream that was passed in to the Workbook constructor after a Save(stream, saveFormat) operation is performed on the workbook?

The same behavior does not exist on the Aspose.Words side... performing a Save(stream, saveFormat) on the Document object does not close the source stream passed in when the Workbook object was created.

In my opinion the implementation is correct in the Document class... a class should not be disposing a stream that it does not own! This should be left to the caller to take care of.

If this is by design, is there a way to indicate to the Workbook class that it should not dispose the stream passed in to the constructor?

Hi,

Which version of Aspose.Cells for .NET you are using? Could you give us your sample code for it, we will check it soon.

Thank you.

Aspose.Cells - v5.1.2.0 and Aspose.Words - v9.4.0.0

Sample Code:

public static void ConvertWordToPdf(Stream sourceStream, Stream targetStream)
{
Aspose.Words.LoadOptions options = new Aspose.Words.LoadOptions();
options.LoadFormat = Aspose.Words.LoadFormat.Docx;
Document document = new Document(sourceStream, options);
document.Save(targetStream, Aspose.Words.SaveFormat.Pdf);
sourceStream.Seek(0, SeekOrigin.Begin); // This works!!!
}

public static void ConvertExcelToPdf(Stream sourceStream, Stream targetStream)
{
Workbook workbook = new Workbook(sourceStream, Aspose.Cells.LoadFormat.Xlsx);
workbook.Save(targetStream, Aspose.Cells.SaveFormat.Pdf);
sourceStream.Seek(0, SeekOrigin.Begin); // throws ObjectDisposedException
}

The first method is for Words... it allows me to access the source stream object after the Save method has been called on the Document class (the right way IMO). The second method is for Cells... any attempt to access the sourceStream after the Save method on the Workbook class throws an ObjectDisposedException exception (bad... Workbook does not own the stream so it should not dispose/close it).

Hi,

Please try the attached latest version/fix v5.2.0.5.

It works just fine according to your needs.

Here is my test code:
FileStream stream = new FileStream(“e:\test\Book1.xlsx”, FileMode.Open);
Workbook book = new Workbook(stream, new LoadOptions(LoadFormat.Xlsx));
book.Worksheets[0].Cells[“AI00”].PutValue(0);
MemoryStream tstream = new MemoryStream();
MessageBox.Show(stream.Length.ToString());
book.Save(tstream, SaveFormat.Pdf);
MessageBox.Show(stream.Length.ToString());
stream.Seek(0, SeekOrigin.Begin); //OK


Thank you.


Thanks for the updated version Amjad. I can confirm the issue is now fixed for source streams containing data for LoadFormat.Xlsx. I can still get it to fail with the same ObjectDisposedException when testing with a Csv source stream though (LoadFormat.CSV). Would it be possible for you to run this test against all formats you support in Cells to confirm that the issue is indeed fixed? Also, will you be releasing a new version publicly that will incorporate this fix?

Hi,

Thanks for pointing it out.

Yes, we have found the error as you have mentioned for CSV file format. We will figure it out soon.
I have logged your issue into our issue tracking system with an id: CELLSNET-22557.

Moreover, we did release our next official version v5.2.1 today, you can use this version but I am afraid, this would only fix the steaming issue for XLS or XLSX file formats.

Thank you.

Hi Ranjeet,

Please use the attached updated version Aspose.Cells5.2.1.1.zip. The issue has been resolved.

Thanks,

Thanks. Its working correctly now. Can I assume that this fix will make it into the next public release?

Hi,

Yes, sure, the next official release would include the functionality. Well, you may use our latest fix that we attached here in this thread in previous post. You can use the hot fix for your requirements as long as you wish; it will behave like an official release. For your information, it is an intermediate kind of version which is provided as a fix against some features and bugs.


Thank you.