There is a code
private void buttonAct_Click(object sender, EventArgs e)
{
try
{
_excelApp = new Excel.Application();
_wkb = _excelApp.Workbooks.Open(fileName,
Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing);
Excel.Worksheet worksheet = (Excel.Worksheet)_wkb.Worksheets[1];
Excel.Range excelRange = worksheet.UsedRange;
object[,] valueArray = (object[,])excelRange.get_Value(
Excel.XlRangeValueDataType.xlRangeValueDefault);
//access the cells
for (int row = 1; row <= worksheet.UsedRange.Rows.Count; ++row)
{
articul = valueArray[row, 1].ToString();
}
}
catch (Exception ex)
{
throw ex;
}
finally
{
//clean up stuffs
_wkb.Close(false, Type.Missing, Type.Missing);
Marshal.ReleaseComObject(_wkb);
_excelApp.Quit();
Marshal.FinalReleaseComObject(_excelApp);
}
}
When you open an Excel workbook, this error will get thrown:
It is impossible to bring a COM object of type "Microsoft.Office.Interop.Excel.ApplicationClass" to the interface type "Microsoft.Office.Interop.Excel._Application". The operation failed because the QueryInterface COM component call for the interface with IID "{000208D5-0000-0000-C000-000000000046}" returned the following error: An error occurred while loading the library. (Exception from HRESULT: 0x80029C4A (TYPE_E_CANTLOADLIBRARY)).
I ask for help. Thank you
User contributions licensed under CC BY-SA 3.0