Problem accesing Excel sheet from model program

Locked Problem accesing Excel sheet from model program

  • 2012年3月23日 上午 08:29
     
     

    Hello all,

    I am trying to make a  model which heavily depends on data. For this reason i need to access an excel sheet to find the required data from the model program. The code has no error. However exploring the model gives an error.

    "1 fatal execution failure: Method Microsoft.Office.Interop.Excel.ApplicationClass..ctor doesn't have an entry point.
    Setting type "Microsoft.Office.Interop.Excel.ApplicationClass" to native with "Microsoft.Xrt.Runtime.NativeTypeAttribute" or in XRT.Config file might solve the problem. Spec Explorer 0 0 "

    I cannot find a solution yet. help needed !!!

    Thanks,

    Vivek

所有回覆

  • 2012年3月23日 下午 01:26
     
     

    Hi Vivek,

    Do you tried already adding this attribute to your model-namespace:
    [assembly: NativeType(typeof(Sample.MyLoader))]
    and replaced "Sample.MyLoader" with the method accessing the Excel-application-objects?
    Replacing "Sample.MyLoader" with just the Excel-application-object should also work as mentioned in the error message...

    Hope it helps.

    P.S.:

    A full example to reading external data is shown on the Spec Explorer Team Blog:
    http://blogs.msdn.com/b/specexplorer/archive/2011/08/02/how-to-initialize-the-initial-state-from-an-external-source.aspx

  • 2012年3月23日 下午 02:33
     
     

    HI, Bububa

    I have already tried that approach

    [

    assembly: Microsoft.Xrt.Runtime.NativeType("Microsoft.Office.Interop.Excel.ApplicationClass")] but it runs into another problem 

    Microsoft.Xrt.RecoverFromFatalErrorException: cannot retrieve generic definition of Microsoft.Office.Interop.Excel.Workbooks.Open

    Any Suggestions!!!

  • 2012年3月23日 下午 04:39
     
     已答覆

    Hi Vivek,

    my idea is that you made just

    Microsoft.Office.Interop.Excel.ApplicationClass
    native, but not also
    Microsoft.Office.Interop.Excel.Workbooks

    You can try to
    * Add all classes you find in your error messages with the native attribute.
    Or (I have this setup):
    * Put all your Excel access methods into an own project (project "Helper").
    * Add this project ("Helper") to your references and make only your own Helper class native.

    Hope someone else has an even better solution for you.

    • 已提議為解答 Yiming Cao 2012年3月26日 上午 05:22
    • 已標示為解答 Vivek.Vishal 2012年3月26日 上午 08:58
    •  
  • 2012年3月26日 上午 05:21
     
     已答覆 包含代碼

    Hi Vivek,

    It's very likely that Office Interop calls into native code which is not executable by Spec Explorer, so the direction that bububa suggested should be the way to go. You probably want to set all classes under Microsoft.Office.Interop.Excel to native. You can either do it following bububa's suggestion and creating a wrapper for all interop calls and set the wrapper class to native, or alternatively use a regular expression to set all all classes to native in a batch, like:

    [assembly: NativeType("Microsoft.Office.Interop.Excel.*")]

    Thanks, Yiming

    • 已標示為解答 Vivek.Vishal 2012年3月26日 上午 08:58
    •