RE: Excel: version 15 - Office 365, Interop: Microsoft Excel 15.0 Object Library, Visual Studio: 2012
I am have a nagging problem with a C# app that loads data from Excel spreadsheets into a database. Sometimes it works file, but periodically, the app will crash at random points in the middle of reading an Excel file, with the error message "Exception from HRESULT: 0x800A01A8".
I open the file as follows:
Excel.Application app = new Excel.Application();
Excel.Workbook workBook = app.Workbooks.Open(fileName, Type.Missing, true);
Excel.Worksheet workSheet = _workBook.Worksheets[1];
where "fileName" is a valid excel xlxs file. I then read the contents of various cells with the following:
int rowIndex = ...
int columnIndex = ...
string result = "";
Excel.Range range = (Excel.Range)workSheet.Cells[rowIndex, columnIndex];
if (range.Value != null)
result = range.Value.ToString().Trim();
The blowup occurs because the workSheet object somehow became corrupted.
A possibly related issue is that when an xlxs file is opened directly with Excel, two instances of Excel will appear, one with the correct file, and the other with one of the files that were previously being read.
I have looked at other postings on this issue and confirmed, for example, that bluetooth is not enabled, and that there are no files in any "xlstart" folders.
Any ideas?