[Solved] Pass an array from OOBasic to C++ uno Service

Java, C++, C#, Delphi... - Using the UNO bridges
Post Reply
saleem145
Posts: 130
Joined: Mon Jul 02, 2012 4:47 pm

[Solved] Pass an array from OOBasic to C++ uno Service

Post 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
Last edited by Hagar Delest on Fri Jul 13, 2012 11:40 pm, edited 2 times in total.
Reason: tagged [Solved].
OpenOffice 3.4.0
Mac OS X 10.5.8
saleem145
Posts: 130
Joined: Mon Jul 02, 2012 4:47 pm

Re: OO Basic Question about Named Range

Post by saleem145 »

Actually getCellRangeByName might do this job.

Saleem
OpenOffice 3.4.0
Mac OS X 10.5.8
saleem145
Posts: 130
Joined: Mon Jul 02, 2012 4:47 pm

Re: OO Basic Question about Named Range

Post 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
OpenOffice 3.4.0
Mac OS X 10.5.8
User avatar
Charlie Young
Volunteer
Posts: 1559
Joined: Fri May 14, 2010 1:07 am

Re: OO Basic Question about Named Range

Post 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))

Apache OpenOffice 4.1.1
Windows XP
saleem145
Posts: 130
Joined: Mon Jul 02, 2012 4:47 pm

Re: How to pass an array from OOBasic to c++ uno Service

Post by saleem145 »

oArray = ...getCellRangeByName("name").getDataArray()

does the job....i was missing the getDataArray() in my code.

Thanks,

Saleem
OpenOffice 3.4.0
Mac OS X 10.5.8
Post Reply