Monday 15 July 2013

Boo - Excel Automation, trouble selecting ranges -


I am checking Boo and thought that it would try to convert some useful VB scripts that Excel (2007, in this example) a lot of things seem to be translated very easily, although I have a lot of difficulty in choosing a range - whenever I try to get them or I am a target invoice administration member Not found

  Def CreateInstance (PROGID): type = System.Type.GetTypeFromProgID (PROGID) return type () XtraDuck = CreateInstance ( "Excel.Application below) Example I have run booish A1" ") xl.Visible = True xl.Workbooks.Add sht = xl.ActiveSheet #next line as duck = duck = sht.Range (as exception RNG Throws ")  

Some things work fine, like setting the property of the name of the letter and so on, but how do I work with categories? Are there some special methods that VB hides that I need to call, and if so, how do I get them?

Cheers,

Lenny.

The range is actually a property, and this is a special property in which it works as an index, which means that it is the array- or dictionary, in most of the words, that means that you < Code> sht.Range ["A1"] . It is syntactic sugar, and in fact it has reached like any other method, that is:

  sht.get_range ("A1", system. Reflection.Missing.Method)  

I tried to use Boo, Ruby and IronRubi to repeat my code using sentence, Chinese style and clear method call. In IronRuby, I can get it to work flawlessly, but in the only 32-bit interpreter in regular ruby, which is 32-bit app on my configuration, it also works fine 64- In Bit Interputer, the range property was never resolved correctly.

So I suspected that the Beo Interactive Shell was running in 64-bit mode and because of this the interop was unsuccessful. Unfortunately, after setting up my Local Boho Binaries to use 32-bit mode for CORFLAGS.exe, the same issue was rediscovered, so I do not think this is a real problem.

  Import Microsoft.Office.Interop.Excel Import System.Runtime.InteropServices xl_type = typeof (application) .GetCustomAttributes: Clearly with Excel DotNet Interop Library, With the Interop services namespace, so the import like (CoClassAttribute) is true) [0] .CoClass xl = xl_type () xl.Visible = true xl.Workbooks.Add  

Then :

  Xl.Range ["A1", "A2"]. Value = 12 xl.Range ["A1", System.Type.Missing] .Value = "Alpha" (xl.ActiveSheet as Worksheet). ["A1", "A2"]. Value 2 = 'whatever'  

All these things, but they essentially require you to leave "Scripty" which you use with late bondage (which is your duck Is typing).

One difference from the correct VB / VBScript for most languages ​​(except for C # 4.0) is that, generally, alternative parameters are not transparently controlled, so when you use the optional parameters (By changing with System.Type.Missing or System.Reflection equals), you will have to look at the API more carefully to deal with those methods. You can find it through Excel Interop docs, although you can use reflection to identify alternatively marked parameters if you find it easier than searching.

Because the Ruby's compulsive work is the right solution for objects, I suspect that Bo has a missing feature (or bug) in COM interop scenarios.

Edit:; The issues described in his post may also apply to bu


No comments:

Post a Comment