How can I check if a worksheet object has been Close()''ed

I think I have only hit this problem when jumping around code in the debugger but I have gotten an error when I call workbook.Close(...) more than once.

I already check that (workbook != null) but I would like to check something else to prevent an error.

I tried "(workbook.ActiveSheet != null)" but that didn't worked when the workbookk has been closed.


Any ideas?

1 Reply

MW Melba Winshia Syncfusion Team August 2, 2007 11:05 AM UTC

Hi Scott,

Thank you for your interest in Essential XlsIO.

We do not have any API to check if a worksheet object has been closed or not. But you can you can check this by using below code snippet.

[C#]

try
{
workbook.Close();
}
catch (System.NullReferenceException ex)
{
MessageBox.Show("workbook is already closed");
}


Please refer the sample in the below link which illustrates the above.

http://websamples.syncfusion.com/samples/XlsIO.Windows/66721/main.htm

Please try this and let me know if this helps.

Thanks,
Melba

Loader.
Up arrow icon