How can read the range as a dictionary?

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
luofeiyu
Posts: 34
Joined: Thu Sep 14, 2017 2:11 am

How can read the range as a dictionary?

Post by luofeiyu »

How can read the range "A1:B4" as a dictionary with oobasic?

Code: Select all

    A            B
1 start        2024
2 length        10
3 rrr           0.1
4 pgr          0.03
LibreOffice 7.4.7.2 on Debian 12
User avatar
Hagar Delest
Moderator
Posts: 32971
Joined: Sun Oct 07, 2007 9:07 pm
Location: France

Re: How can read the range as a dictionary?

Post by Hagar Delest »

I think you need to tell more.
What is the intent, what are the input and output variables?
LibreOffice 24.8 on Linux Mint Debian Edition (LMDE Faye) and 24.8 portable on Windows 10
luofeiyu
Posts: 34
Joined: Thu Sep 14, 2017 2:11 am

Re: How can read the range as a dictionary?

Post by luofeiyu »

Create a dictionary such as :

Code: Select all

dict = {"start":2024,"length":10,"rrr":0.1,"pgr":0.03}
I can read the range :

Code: Select all

Dim oSheet as Object
Dim oCell as Object
oSheet = ThisComponent.CurrentController.getActiveSheet()
oCell = oSheet.getCellRangeByName("A1:B4")
How can assign it as a dictionary in oobasic then?
LibreOffice 7.4.7.2 on Debian 12
User avatar
Zizi64
Volunteer
Posts: 11434
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: How can read the range as a dictionary?

Post by Zizi64 »

Code: Select all

oCell = oSheet.getCellRangeByName("A1:B4")
This is a range but not a single cell. (It is only a difference in the names, but it is better to name a range as oRange.)

Your cellrange is a two dimensional Array. The names are located on the first "column", and the values in the second "column". You can handle this array by usage the x/y dimension values.

Code: Select all

dict = {"start":2024,"length":10,"rrr":0.1,"pgr":0.03}
I do not know what is the "dictionary in the StarBasic, but (maybe) you can set (fill-in) the values of the "dictionary" by usage the Array dimensions
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
User avatar
Zizi64
Volunteer
Posts: 11434
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: How can read the range as a dictionary?

Post by Zizi64 »

Here is some information about the VBA compatible "Collections":

viewtopic.php?p=57761#p57761
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
User avatar
Lupp
Volunteer
Posts: 3632
Joined: Sat May 31, 2014 7:05 pm
Location: München, Germany

Re: How can read the range as a dictionary?

Post by Lupp »

luofeiyu wrote: Fri Jan 17, 2025 4:08 am ... as a dictionary with oobasic?
How do you want to use the term "dictionary" here? I don't see one.
Do you mean a kind of lookup table?
In what way do you want to point AOO(OO.o/LibO) to the specific range?
On Windows 10: LibreOffice 24.8.3 and older versions, PortableOpenOffice 4.1.7 and older, StarOffice 5.2
---
Lupp from München
JeJe
Volunteer
Posts: 2971
Joined: Wed Mar 09, 2016 2:40 pm

Re: How can read the range as a dictionary?

Post by JeJe »

Do you mean the ScriptForge.Dictionary service?

https://help.libreoffice.org/latest/en- ... bPAR=BASIC

(I claim the prize if this is the right guess...)
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
JeJe
Volunteer
Posts: 2971
Joined: Wed Mar 09, 2016 2:40 pm

Re: How can read the range as a dictionary?

Post by JeJe »

There's also the enumerable map

viewtopic.php?p=385856#p385856
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
Post Reply