
Untitled
By: a guest on
May 7th, 2012 | syntax:
None | size: 0.97 KB | hits: 20 | expires: Never
How to verify if a file is a valid excel spreadsheet?
_app = new Application()
{
Visible = false,
DisplayAlerts = false, // <-- I don't want to remove this.
AskToUpdateLinks = false,
};
_workbooks.Open(filename);
_workbook = _workbooks.get_Item(1); // 1-based.
_worksheets = _workbook.Sheets;
XlFileFormat.xlTextMac
XlFileFormat.xlTextMSDOS
XlFileFormat.xlTextPrinter
XlFileFormat.xlTextWindows
XlFileFormat.xlExcel12
XlFileFormat.xlExcel7
XlFileFormat.xlExcel8
XlFileFormat.xlExcel9795
bool validFile = ( f == XlFileFormat.xlExcel12 )
|| ( f == XlFileFormat.xlExcel7 )
|| ( f == XlFileFormat.xlExcel8 )
|| ( f == XlFileFormat.xlExcel9795 );
int countBefore = _workbooks.get_Count();
_workbooks.Open(filename);
int countAfter = _workbooks.get_Count();
if (countBefore == countAfter) {
// The file failed to load.
}