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

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
Mons1990
Posts: 5
Joined: Wed Nov 23, 2016 4:44 pm

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

Post by Mons1990 »

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

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
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Can't get data from sheet as array

Post by Villeroy »

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
Mons1990
Posts: 5
Joined: Wed Nov 23, 2016 4:44 pm

Re: Can't get data from sheet as array

Post by Mons1990 »

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
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Can't get data from sheet as array

Post by Villeroy »

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

Post by einstein »

Try with:

Code: Select all

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
Mons1990
Posts: 5
Joined: Wed Nov 23, 2016 4:44 pm

Re: Can't get data from sheet as array

Post by Mons1990 »

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
NzKb13
Posts: 3
Joined: Fri Nov 13, 2020 10:28 am

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

Post by NzKb13 »

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