Interop Excel LinEst method does not work with DISP_E_TYPEMISMATCH

I am having a problem executing an Excel Linest function.

My program is like

MyExcel.Application xl = new MyExcel.Application(); MyExcel.WorksheetFunction wsf = xl.WorksheetFunction; List<int> x = new List<int> { 1, 2, 3, 4 }; List<int> y = new List<int> { 11, 12, 45, 42 }; object o = wsf.LinEst(x, y, true, true); 

And the namespace using MyExcel = Microsoft.Office.Interop.Excel;

The program compiles smoothly, but at runtime it throws an error

 {System.Runtime.InteropServices.COMException (0x80020005): Type mismatch. (Exception from HRESULT: 0x80020005 (DISP_E_TYPEMISMATCH)) 

This is actually the first time I use the Excel function. Therefore, I cannot continue. If someone has dealt with this situation and decided, please help me.

I am using C # 3.0.

+2
source share
1 answer

Convert lists x and y to an array:

  MyExcel.Application xl = new MyExcel.Application(); MyExcel.WorksheetFunction wsf = xl.WorksheetFunction; List<int> x = new List<int> { 1, 2, 3, 4 }; List<int> y = new List<int> { 11, 12, 45, 42 }; //object o = wsf.LinEst(x, y, true, true); object o = wsf.LinEst(y.ToArray(), x.ToArray(), false, true); 
+1
source

Source: https://habr.com/ru/post/1307675/


All Articles