15473

Interop Excel method LinEst failing with DISP_E_TYPEMISMATCH

Question:

I am facing a problem while making Excel's LinEST function.

My program goes 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 is using MyExcel = Microsoft.Office.Interop.Excel;

The program is compiling smoothly but at runtime it is throwing an error

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

Actually this is the first time I am using Excel function .. so I am unable to proceed further. If any one has run thru this kind of situation and has solved, please help me.

I am using C# 3.0.

Answer1:

Convert the lists x and y to 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);

Recommend

  • Android Studio Webview not calling photo gallery
  • Simulate User Input To Call Script Multiple Times With Different Parameters
  • FrameLayout in reverse
  • Simple-as-possible task schedule to call web page
  • Handling partial/incomplete dates in .NET
  • Get source property type from BindingExpression
  • Zend 2: How to override module's configuration file?
  • Syntax highlighting of Fortran 77 comments not working in vim
  • Second layout is not showing with include tag in android studio
  • How to open camera in android webview?
  • Python SKLearn: How to Get Feature Names After OneHotEncoder?
  • How to get metadata from Media objects
  • GC.start has no effect in Pry, but does in IRB
  • Year over Year Stats from a Crossfilter Dataset
  • How to define something in JavaScript [closed]
  • Amazon Elastick BeanStalk error: Failed to create the AWS Elastic Beanstalk application version
  • reshape/remould data frame to create normalized bar chart and pie chart
  • Google App Engine Datastore: Dealing with eventual consistency
  • How to decleare char *const argv[] in swift [duplicate]
  • How to encrypt Connectionstring written in web.config from codebehind?
  • Update cell query for Excel ADO from Delphi
  • How to get rgb from transparent pixel in js
  • Can someone explain this Java code (formatting the output using System.out.format) to me?
  • Grails - How to implement a foreign key relationship not using an id column?
  • Capture SIGFPE from SIMD instruction
  • Using Service Component Runtime
  • Accessing Arguments, Workflow Variables from custom activities
  • How to use FirstOrDefault inside Include
  • How do I use TagLib-Sharp to write custom (PRIV) ID3 frames?
  • PHP Permalinks.. how to change?
  • media foundation H264 decoder not working properly
  • CAS 4 - Not able to retrieve the LDAP groups after successful authentication
  • Running R's aov() mixed effects model from Python using rpy2
  • What does the “id” field in an Android “Google Play Music” broadcast intent correspond to?
  • Access to a Matlab gui from the web
  • ReferenceError: TextEncoder is not defined
  • XSLT Transformation to validate rules in XML document