Boo - Excel Automation, selection range selection

I study Boo and thought it would be a useful exercise to try to convert a couple of venerable VB scripts that automate Excel (2007, in this case). Many things seem to be very easy to translate, however, I have a huge number of problems with selecting ranges - whenever I try to get or set them, I get a TargetInvocationException element that is not found.

Here is an example (cut down) that I used in booish:

def CreateInstance(progid):
    type = System.Type.GetTypeFromProgID(progid)    
    return type()   

xl as duck = CreateInstance("Excel.Application")
xl.Visible = true
xl.Workbooks.Add

sht as duck = xl.ActiveSheet
#Next line throws exception
rng as duck = sht.Range("A1")

Some things work fine, for example by setting the Name property of a sheet, etc., but how can I work with ranges? Are there any special methods that VB hides that I will need to call, and if so, how can I find them?

Greetings

Lenny.

+3
1

, , Indexer, , , . , sht.Range["A1"]. , , , :

sht.get_Range("A1",System.Reflection.Missing.Method)

Boo, Ruby IronRuby, , , . IronRuby , 32- . Ruby, 32- , . 64- Range .

, , Boo Interactive Shell 64- , - interop . , , Boo 32- CORFLAGS.exe, , .

Excel Dotnet Interop, Interop, :

import Microsoft.Office.Interop.Excel
import System.Runtime.InteropServices

xl_type=typeof(Application).GetCustomAttributes(typeof(CoClassAttribute),true)[0].CoClass
xl=xl_type()
xl.Visible=true
xl.Workbooks.Add

:

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

, , "Scriptiness", , ( ).

VB/VBScript, ( # 4.0), , , , , API, ( System.Type.Missing System.Reflection). Excel interop, , , , , , , , .

Ruby , , COM- Boo ( ).

: Sam Ng # 4.0; , , , .

+3

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


All Articles