I already did some search here on SO, on this, this, this and more, but no clue, so I'm going to have to ask you guys.
I'm trying to open an Excel file via Interop, and I have Office 2007 installed, so I'm using Microsoft.Office.Interop.Excel
version 14.0
.
When I try to open a valid xls
file, everything runs fine.
But if I try to open an invalid file (like a bitmap, or an executable) via Interop, Excel opens it without complain or warning.
How can I detect Excel has an invalid workbook file loaded, without blocking with an alert ?
I'm trying to write a unit test of my Excel object reader. One of the cases is to try to open an invalid file.
Some code to help: Application Creation:
_app = new Application()
{
Visible = false,
DisplayAlerts = false, // <-- I don't want to remove this.
AskToUpdateLinks = false,
};
Workbook opening:
_workbooks.Open(filename);
_workbook = _workbooks.get_Item(1); // 1-based.
_worksheets = _workbook.Sheets;
EDIT:
Just to add 1 more information: Excel loads the invalid file. If DisplayAlerts
is set to true, it complains (open a dialog) informing the workbook seems to be corrupted, but if DisplayAlerts
is set to false, it loads the file just as below: