Page 1 of 1
[Solved] Pass an array from OOBasic to C++ uno Service
Posted: Thu Jul 12, 2012 11:33 pm
by saleem145
Hello,
I know how to assign a variable in basic a value from the spreadsheet. An in below,
Dim start_date
start_date = ThisComponent.Sheets(0).GetCellByPosition(0,0).Value
How do I assign a variable a range of values -- where the range is a named range?? I want to do something like
Dim name
name = ThisComponent.Sheets(0).GetCellsByName("NameOfRange").Value
Where names will be an array...
Thanks,
Saleem
Re: OO Basic Question about Named Range
Posted: Fri Jul 13, 2012 12:35 am
by saleem145
Actually getCellRangeByName might do this job.
Saleem
Re: OO Basic Question about Named Range
Posted: Fri Jul 13, 2012 1:08 am
by saleem145
Hello,
I can define the variables as arrays
Dim compo_fields(0,3) as String
Initialize them manually in OOBasic and then pass them into C++ uno service. It works.
Instead of initializing these variable manually I want to assign the contents of a named range.
Saleem
Re: OO Basic Question about Named Range
Posted: Fri Jul 13, 2012 4:24 am
by Charlie Young
saleem145 wrote:Hello,
I can define the variables as arrays
Dim compo_fields(0,3) as String
Initialize them manually in OOBasic and then pass them into C++ uno service. It works.
Instead of initializing these variable manually I want to assign the contents of a named range.
Saleem
You can get the contents of a named range in one big gulp
Code: Select all
oArray = ...getCellRangeByName("name").getDataArray()
This may not work directly with your add-in function call though, and you'll need to do
Code: Select all
Dim newArray(UBound(oArray).UBound(oArray(0)))
for i = 0 to UBound(oArray)
for j = 0 to UBound(oArray(0))
newArray(i,j) = oArray(i)(j)
next j
next i
Note the subscripting.
To use one of your addin functions in Basic (or JavaScript, or Python, or...), you can use
XFunctionAccess, where you need that AddinInfo stuff we discussed earlier.
Code: Select all
Dim svc As Object
Dim result
svc = createUnoService("com.sun.star.sheet.FunctionAccess")
result = svc.callFunction("blahblah.myService1_implementation.ServiceName.Functionname",Array(arguments))
Re: How to pass an array from OOBasic to c++ uno Service
Posted: Fri Jul 13, 2012 1:35 pm
by saleem145
oArray = ...getCellRangeByName("name").getDataArray()
does the job....i was missing the getDataArray() in my code.
Thanks,
Saleem