Retrieve / Modify custom properties

Creating a macro - Writing a Script - Using the API

Retrieve / Modify custom properties

Postby jacklafrip » Fri Jun 03, 2011 1:17 am

Dear all,

I have a document that uses some custom properties.
These properties are used in other documents, so I want to use them.
I tried to retrieve the custom properties and modify the texts associated with them.
Code: Select all   Expand viewCollapse view
XPropertySet xCustomProperty = (XPropertySet)((XMultiServiceFactory)TextDocument).createInstance("com.sun.star.text.textfield.docinfo.Custom");
xCustomProperty.setPropertyValue("Name", new uno.Any("CustomProperty1"));
xCustomProperty.setPropertyValue("CurrentPresentation", new uno.Any("TextForProperty"));
xCustomProperty.setPropertyValue("IsFixed", new uno.Any(true));


No modifications could be seen on the document.
What did I do for a mistake ?

Thanks
OpenOffice 3.3 on WindowsXP / VisualStudio 2005
jacklafrip
 
Posts: 7
Joined: Mon May 30, 2011 11:41 am

Re: Retrieve / Modify custom properties

Postby JohnSUN-Pensioner » Fri Jun 03, 2011 12:21 pm

Useful Macro Information For OpenOffice.org By Andrew Pitonyak
5.18.3. Master Fields
 Edit: PS. At "OOME_3_0.odt" it is 14.8.2. Creating and adding text fields 
I may not have a lot to give but what I got I'll give to you...
Apache OpenOffice 4.1.4, LibreOffice 5.4.2.2 (x64) on Windows 7
If you think that I did not answer your question, make allowances for my imperfect English
User avatar
JohnSUN-Pensioner
Volunteer
 
Posts: 761
Joined: Fri Jan 14, 2011 1:21 pm
Location: Kyiv, Ukraine

Re: Retrieve / Modify custom properties

Postby Pashahasband » Wed Aug 07, 2019 5:26 pm

Hi, I ran into the same problem, was there a solution?
LibreOffice 6.2.4.2 (x64)
Windows 10
Pashahasband
 
Posts: 6
Joined: Thu Aug 01, 2019 4:21 pm

Re: Retrieve / Modify custom properties

Postby Villeroy » Wed Aug 07, 2019 5:51 pm

The answer is the same for 90% of all these questions.
1. Read the above linked book.
2. Install MRI. [Tutorial] Introduction into object inspection with MRI
No MRI, no macros.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04, no OpenOffice, LibreOffice 6.x
User avatar
Villeroy
Volunteer
 
Posts: 27381
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Retrieve / Modify custom properties

Postby Pashahasband » Wed Aug 07, 2019 6:05 pm

I read the article above, but there is an example with fieldmaster, writing to user variables is normal for me. But writing to docinfo does not occur. Could you give an example of an entry in docinfo?
LibreOffice 6.2.4.2 (x64)
Windows 10
Pashahasband
 
Posts: 6
Joined: Thu Aug 01, 2019 4:21 pm

Re: Retrieve / Modify custom properties

Postby Villeroy » Wed Aug 07, 2019 6:26 pm

You know what? I don't know. I start MRI and look it up!
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04, no OpenOffice, LibreOffice 6.x
User avatar
Villeroy
Volunteer
 
Posts: 27381
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Retrieve / Modify custom properties

Postby Lupp » Wed Aug 07, 2019 10:20 pm

The UserDefinedProperties are implemented as a PropertyBag. This service inherits the interface XPropertyContainer which provides the functions you need.
See https://api.libreoffice.org/docs/idl/re ... ainer.html e.g.
On Windows 10: LibreOffice 6.2 and older versions, PortableOpenOffice 4.1.5 and older, StarOffice 5.2
---
Lupp from München
User avatar
Lupp
Volunteer
 
Posts: 2564
Joined: Sat May 31, 2014 7:05 pm
Location: München, Germany

Re: Retrieve / Modify custom properties

Postby JeJe » Wed Aug 07, 2019 11:18 pm

in Basic:

Code: Select all   Expand viewCollapse view

propname = "New Property"
propvalue = "fish"

   with ThisComponent.DocumentProperties.UserDefinedProperties

      if .getPropertySetInfo().hasPropertyByName(propname) = false then
         .addProperty(propname,128,"")
      end if
         .setPropertyValue(propname, propvalue)
   
         MSGBOX .getPropertyValue(propname)
   end with

Openoffice 4.1.2
Windows 8
JeJe
Volunteer
 
Posts: 629
Joined: Wed Mar 09, 2016 2:40 pm


Return to Macros and UNO API

Who is online

Users browsing this forum: No registered users and 10 guests