3

Trying to do this:

let excel = AutomationFactory.CreateObject "Excel.Application"
excel?Visible <- true
excel?workbooks?Add ()

Although EXCEL.EXE does appear in the Task Manager when I run that code, the excel object apparently has no properties, which makes the rest of the code pretty tough to execute. (If I place let allProps = excel.GetType().GetProperties(BindingFlags.Public ||| BindingFlags.NonPublic) after the first line, it evaluates to an empty PropertyInfo array.)

In examples of Silverlight/Excel interop that I've seen, everyone simply does what I'm trying to do, with no problems. Not sure why I'm having this issue...??

Jack P.
  • 11,487
  • 1
  • 29
  • 34
MiloDC
  • 2,373
  • 1
  • 16
  • 25
  • Can you tell us the version of: Excel, .NET, and F#? I also see that you are using the dynamic operator (? with <-) It is used as an operator for dynamic method and property calls. You must provide your own implementation of it, have you done that? – ninegrid Jun 05 '13 at 23:51
  • Excel 2007, .NET 4, and as stated in the title of this question, F# 2.0. Yes, I've coded the dynamic setter, but again `excel.GetType().GetProperties()` returns an empty array. My implmentation of `?<-` should have nothing to do with that. – MiloDC Jun 06 '13 at 00:23

1 Answers1

0

AutomationFactory.CreateObject creates an automation server, which is intended to be used via dynamic dispatch. http://msdn.microsoft.com/en-us/library/ff457794(v=vs.95).aspx. To me, this makes sense, since the properties available would be defined by the object being automated.

Using object.GetType().GetProperties() will only give you pre-compiled properties of the object, not the dynamic properties.

If you are automating excel to create a spreadsheet, you may have an easier time using a third party library that does not use Excel automation. Many of them are listed in this answer: Create Excel (.XLS and .XLSX) file from C#

Community
  • 1
  • 1
John Atwood
  • 1,505
  • 10
  • 19