[Solved] Can't get data from sheet as array

Creating a macro - Writing a Script - Using the API

[Solved] Can't get data from sheet as array

Postby Mons1990 » Wed Nov 23, 2016 4:46 pm

Hi, I'm moving my first steps with OpenOffice Basic, I found the way to do all what I need except one thing that still no works.
I have a single column with two values and I want to pass them to the macro as an array.

Code: Select all   Expand viewCollapse view
Option Explicit

Sub prova()
    Dim FoglioAttivo As Object
    FoglioAttivo = ThisComponent.getCurrentController.getActiveSheet
    Dim dimc(1, 0) As Integer
    dimc = FoglioAttivo.getCellRangebyName("A1:A2").getDataArray()
    print dimc(0, 0)
End Sub


shows me error "Variable Object not set" on the "print" line.

Where's my fault? I tried in the same way the setDataArray instruction in another part of the program and it works.

Thank you in advance
Last edited by Hagar Delest on Thu Nov 24, 2016 9:29 pm, edited 1 time in total.
Reason: tagged [Solved].
Office suite used: LibreOffice Fresh 5.2 by Arch Linux RepoS

--
Mons
Mons1990
 
Posts: 5
Joined: Wed Nov 23, 2016 4:44 pm

Re: Can't get data from sheet as array

Postby Villeroy » Wed Nov 23, 2016 7:26 pm

Mons1990 wrote:Where's my fault?

You do not debug.
You do not read documentation.
You do not read other peoples code.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
User avatar
Villeroy
Volunteer
 
Posts: 29581
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Can't get data from sheet as array

Postby Mons1990 » Wed Nov 23, 2016 7:40 pm

Villeroy wrote:You do not debug.
True, I tried to install the MRI extension but it shows me an error.
Villeroy wrote:You do not read documentation.
False, I read it but i can't undestand the error.
Villeroy wrote:You do not read other peoples code.
Yes&No. I searched it on Google but i found few examples using the getDataArray() function, and the other error reported were in codes very more difficult then this.
Office suite used: LibreOffice Fresh 5.2 by Arch Linux RepoS

--
Mons
Mons1990
 
Posts: 5
Joined: Wed Nov 23, 2016 4:44 pm

Re: Can't get data from sheet as array

Postby Villeroy » Wed Nov 23, 2016 8:02 pm

Mons1990 wrote:
Villeroy wrote:You do not debug.
True, I tried to install the MRI extension but it shows me an error.

Set a stop mark and inspect your dimc variable.
Select an arbitrary cell range with data, call menu:Tools>Extensions>MRI>MRI <-- selection and then double-click the line starting with DataArray.
Villeroy wrote:You do not read documentation.
False, I read it but i can't undestand the error.

THIS is the documentation: http://www.openoffice.org/api/docs/comm ... eData.html
You may understand better if you would inspect your variables.
Villeroy wrote:You do not read other peoples code.
Yes&No. I searched it on Google but i found few examples using the getDataArray() function, and the other error reported were in codes very more difficult then this.

[UNO, Calc] How to fill spreadsheets cells programmatically

Anyway, this is not VBA. It is for knowlegable programmers only. You can not start a programming career with OpenOffice macros because this is too far beyond beginners level.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
User avatar
Villeroy
Volunteer
 
Posts: 29581
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Can't get data from sheet as array

Postby einstein » Wed Nov 23, 2016 8:53 pm

Try with:
Code: Select all   Expand viewCollapse view
Sub prova()
    Dim FoglioAttivo As Object
    FoglioAttivo = ThisComponent.getCurrentController.getActiveSheet
    dimc = FoglioAttivo.getCellRangebyName("A1:A2").getDataArray()
    For i = 0 To 1
    print dimc(i)(0)
    Next
End Sub

I have removed "Option Explicit"
lo 5.1.6.2 | aoo 4.1.3 | win 7/10
All I know is that I know nothing
User avatar
einstein
 
Posts: 47
Joined: Sat Nov 05, 2016 1:45 am
Location: State of Mexico, México.

Re: Can't get data from sheet as array

Postby Mons1990 » Thu Nov 24, 2016 12:54 pm

Villeroy wrote:Set a stop mark and inspect your dimc variable.
Villeroy wrote:You may understand better if you would inspect your variables.
einstein wrote:Try with
Well, thank you. I found the mistake. The code does not return a multi-dimensional array but an Object that contains an array for every column it read. So I have to use it in the form varname(col)(row).

Villeroy wrote:Anyway, this is not VBA. It is for knowlegable programmers only. You can not start a programming career with OpenOffice macros because this is too far beyond beginners level.
I'm graduating now, I'd like to learn Python immediately later. I was asking because I had to edit some documents with simple macros that i wrote in VBA at University (they have MS Excel), but I have only Linux at home; and I preferred to use OpenOffice Basic and ods instead of GNU Octave and csv.

Thank you.
Office suite used: LibreOffice Fresh 5.2 by Arch Linux RepoS

--
Mons
Mons1990
 
Posts: 5
Joined: Wed Nov 23, 2016 4:44 pm

Re: [Solved] Can't get data from sheet as array

Postby NzKb13 » Mon Feb 01, 2021 11:27 pm

Thank You, It was fine for me. I must say not always easy to find but it's some where on the WWW.
OpenOffice 6.46.2 / Ubuntu 20.04LTS
NzKb13
 
Posts: 3
Joined: Fri Nov 13, 2020 10:28 am


Return to Macros and UNO API

Who is online

Users browsing this forum: No registered users and 6 guests