0

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?

  • why not convert the code to Load the Excel into A DataTable and from there you can write code that inserts the rows in the datatable into the database.. also are you properly Disposing of the Interop Com Objects..? what you have posted probably is not enough information code wise to go by.. please edit the question and post all relevant code that pertains to the current issue that you are experiencing – MethodMan Jun 14 '16 at 20:04
  • This seems like it might be related: http://stackoverflow.com/questions/1563406/what-is-error-code-0x800a01a8-coming-out-of-excel-activex-call It indicates `0x800A01A8` is equivalent to "Object Required". It may happen if the workbook is closed and then a range is accessed afterward. Also related: http://stackoverflow.com/questions/158706/how-to-properly-clean-up-excel-interop-objects?rq=1 – ebyrob Jun 14 '16 at 20:08
  • In regard to object disposal, the Excel objects are properly disposed after use and even the Excel instance is killed, so that is not the issue. Furthermore, this happens on the first Excel file being loaded. In regard to the workbook being closed, the workbook object is untouched during the entire read operation. An outside process may somehow dispose the workbook object, which would then also kill the worksheet object associated with it. – Richard B. Sorensen Jun 15 '16 at 21:13

0 Answers0