Save Stream not being disposed of / IDisposable pattern for Excel component?

Hi,

in some cases it seems to me that as if the stream the Excel component writes an Excel file to is never disposed of or properly closed / flushed. When I generate an Excel Workbook, save it and open the Workbook while my application is running, I sometimes get an error that the Excel file seems to be corrupt. However when I close my controlling application, opening the Excel file works all the time.

This lead me to the asumption the either Dispose() isn’t called on the Stream or that it simply isn’t closed (well, the same as calling Dispose())

BTW Dispose: Would it make sense for the Excel component to implement the IDisposable pattern? I don’t know anything about the resources held by the object, but if there are many or any resources held that are scarce, I would prefer having a deterministic cleanup rather than bet on the GC popping in.

Regards

Kai

Dear Kai,

When Aspose.Excel save an Excel file, this file cannot be accessed by other applications. For example, there is a book1.xls in your driver C. If you use MS Excel to open it, Aspose.Excel cannot save it in the same time.

In earlier version of Aspose.Excel, it cannot read an Excel file opened by other applications. In the latest v3.1.1, this issue is fixed. Which version are you using now?

After saving the file, Aspose.Excel automatically free the resources.

Laurence,

my problem does not have anything to do with locks on the file that MS Excel will hold while the file is open within MS Excel. Thus reading / writing to the file isn’t really a problem.

My only feeling is that the data written to the file by Aspose.Excel isn’t flushed immediately after the Save() method returns thus the file isn’t fully ready yet and contains invalid / incomplete data. When I exit my application, the data seems to be flushed and the file ist just fine.

Regards

Kai

Hi Kai,

Do you write file to stream and then save to disk? Please call Stream.Close() method after you call Excel.Save() method.

Laurence,

I’m calling Save() letting it write to a file; I’m not making use of my “own” streams.

I will try and check with 3.1.1.0 and see whether I can reproduce the problem. Currently we’re on 3.0.6.6

Regards

Kai

Hi Kai,

Actually I release all resources after calling save method. I wrote a window application to open and save file but didn’t find the problem.

Could you please give me a simple sample to show your problem? Thank you very much.

Laurence,

actually all of my ideas are simply based on guesses why the generated Excel files sometimes are fine and the next time they are corrupt. The only hint I have is that when I exit my application, Excel files open just fine. That’s why I came up with my original question(s).

We have just migrated to 3.1.1.0 and run a couple of tests. If you do not read any more news here, the problem got solved.

Thanks for your continued support

Regards

Kai