[Solved] Absolutename from PersistentRepresentation

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
sokolowitzky
Posts: 103
Joined: Mon Sep 15, 2014 7:34 pm

[Solved] Absolutename from PersistentRepresentation

Post by sokolowitzky »

Dear All,

I'm trying to figure out how to get absolute name of a range from cellrangeaddressconversion. This code already returns cellrangeaddress. But I need absolutename.
Anyone has any idea?

Code: Select all

sub bomb
osht=thiscomponent.sheets(0)
Dim oCellRangeAddress As new com.sun.star.table.CellRangeAddress 

ocl = 0 
orw = 1
oCellRangeAddress.Sheet = 0 
oCellRangeAddress.StartColumn = ocl 
oCellRangeAddress.EndColumn = ocl + 23 
oCellRangeAddress.StartRow = orw + 1
oCellRangeAddress.EndRow = orw + 24
oConvx = thiscomponent.createInstance("com.sun.star.table.CellRangeAddressConversion") 
oConvx.Address = oCellRangeAddress
oConvxa = oConvx.persistentrepresentation

msgbox oConvxa
end sub
Last edited by sokolowitzky on Tue Oct 16, 2018 8:47 pm, edited 1 time in total.
Win10-OpenOffice 4.1/LibreOffice 7.4
FJCC
Moderator
Posts: 9280
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: Absolutename from PersistentRepresentation

Post by FJCC »

I am not able to find com.sun.star.table.CellRangeAddressConversion in the API documentation. Where did you find that?
OpenOffice 4.1 on Windows 10 and Linux Mint
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
sokolowitzky
Posts: 103
Joined: Mon Sep 15, 2014 7:34 pm

Re: Absolutename from PersistentRepresentation

Post by sokolowitzky »

I'm not sure, I had just googled it once. You can try, it works.
Win10-OpenOffice 4.1/LibreOffice 7.4
User avatar
RoryOF
Moderator
Posts: 34618
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Absolutename from PersistentRepresentation

Post by RoryOF »

@FJCC: http://www.pitonyak.org/AndrewMacro.pdf mentions it in section 6.6
Apache OpenOffice 4.1.15 on Xubuntu 22.04.4 LTS
FJCC
Moderator
Posts: 9280
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: Absolutename from PersistentRepresentation

Post by FJCC »

Using MRI I am able to see all the properties of of your oConvx object. (Hoja = Sheet)

Code: Select all

(Name)                       (Value Type)             (Value)             (Info.)   (Attr.)    (Handle)  
Address                      .table.CellRangeAddress  -STRUCT-                                   0  
ImplementationId             []byte                   -SEQUENCE-          Pseud     Read_Only       
ImplementationName           string                   ScAddressConver...  Pseud     Read_Only       
PersistentRepresentation     string                   Hoja1.A3:Hoja1.X26                         0  
PropertySetInfo              .beans.XPropertySetInfo  -INTERFACE-         Pseud     Read_Only       
ReferenceSheet               long                     0                                          0  
SupportedServiceNames        []string                 -Sequence-          Pseud     Read_Only       
Types                        []type                   -Sequence-          Pseud     Read_Only       
UserInterfaceRepresentation  string                   A3:X26                                     0  
XLA1Representation           string                   Hoja1!A3:X26                               0  
The closest thing to an absolute address is the XLA2Representation. I suppose you could manipulate that into an absolutes address but OO Basic is clumsy handling strings.

@RoryOF - Thanks for the tip. Andrew must have found that service in the OpenOffice code.
OpenOffice 4.1 on Windows 10 and Linux Mint
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
sokolowitzky
Posts: 103
Joined: Mon Sep 15, 2014 7:34 pm

Re: Absolutename from PersistentRepresentation

Post by sokolowitzky »

I should try to learn using this MRI and other extension but I don't have a coding background and I easily feel like I'm lost. Anyhow thanks.
Now I made up another way to get absolutename. Here I add the code for the people like me. this code creates tags for ranges in a loop.

Code: Select all

REM  *****  BASIC  *****
Sub AddNamedRange1() 
Dim oRange  ' The created range. 
Dim oNamedRanges ' All named ranges.
Dim nameOfRange  ' Name of the named range to create.
Dim oCell   ' Cell object.
Dim oConvxa$
Dim sK1
Dim sK2
Dim ocl1 as integer
Dim orw1 as integer
Dim ocl2 as integer
Dim orw2 as integer
osht=thiscomponent.sheets(0)
for i= 0 to 1
nameOfRange1 = "HST" & 10 + i
oNamedRanges = ThisComponent.NamedRanges
Dim oCellAddress1 As new com.sun.star.table.CellAddress 
oCellAddress1.Sheet = 0 
oCellAddress1.Column = oc11
oCellAddress1.Row = orw1 + 1


ocl1 = 0 
orw1 = 675 + i * 25

ocellrange1=osht.getcellrangebyposition(ocl1 , orw1 + 1 , ocl1 + 23 , orw1 + 24)


sK1 = ocellrange1.absolutename
msgbox sk1
oNamedRanges.addNewByName(nameOfRange1, sK1, ocelladdress1, 0)
nameOfRange2 = "vST" & 10 + i
Dim oCellAddress2 As new com.sun.star.table.CellAddress 
oCellAddress2.Sheet = 0 
oCellAddress2.Column = ocl2
oCellAddress2.Row = orw2 + 1

ocl2 = 25 
orw2 = 675 + i * 25

ocellrange2=osht.getcellrangebyposition(ocl2 , orw2 + 1, ocl2 + 23 , orw2 + 24)


sK2 = ocellrange2.absolutename
msgbox sk2
oNamedRanges.addNewByName(nameOfRange2, sK2, ocelladdress2, 0)

next


end sub
Win10-OpenOffice 4.1/LibreOffice 7.4
User avatar
Zizi64
Volunteer
Posts: 11362
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Absolutename from PersistentRepresentation

Post by Zizi64 »

You can get the oRange itself based on the oSheet and the UserInterfaceRepresentation;
and then the absolute name of the range:

Code: Select all

REM  *****  BASIC  *****

option explicit 

sub test

 Dim oDoc as object
 Dim oSheets as object
 Dim oSheet as object
 Dim oRange as object
 Dim oConvx as object
 Dim oCellRangeAddress As new com.sun.star.table.CellRangeAddress
 
 Dim lCol as long
 Dim lRow as long
 
 Dim sConvxa as string
 Dim sConvxb as string
 Dim sAbsName as string


	oDoc = ThisComponent
	oSheets = oDoc.Sheets
	oSheet = oSheets.GetByIndex(0)

	lCol = 0
	lRow = 1

	oCellRangeAddress.Sheet = 0
	oCellRangeAddress.StartColumn = lCol
	oCellRangeAddress.EndColumn = lCol + 23
	oCellRangeAddress.StartRow = lRow + 1
	oCellRangeAddress.EndRow = lRow + 24
	
	oConvx = thiscomponent.createInstance("com.sun.star.table.CellRangeAddressConversion")
	oConvx.Address = oCellRangeAddress
	
	sConvxa = oConvx.persistentrepresentation
	sConvxb = oConvx.UserInterfaceRepresentation
		
	oRange = oSheet.getCellRangeByName(sConvxb)
	sAbsName = oRange.AbsoluteName
	
	Print sAbsName

end sub
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.
sokolowitzky
Posts: 103
Joined: Mon Sep 15, 2014 7:34 pm

Re: Absolutename from PersistentRepresentation

Post by sokolowitzky »

@Zizi: Thanks. I was thinking about this, but I could not manage the syntax.
Win10-OpenOffice 4.1/LibreOffice 7.4
Post Reply