Page 1 of 1

[Solved] Setting Custom Properties from external application

Posted: Tue Aug 05, 2014 9:07 pm
by iwbnwif
I would like to be able to change some already defined Custom Properties (File -> Properties -> Custom Properties) in the currently active text document from my separate (large) application.

So far I have been able to achieve basically what I want to do by adding the following code to the SimpleBootstrap_cpp example:

Code: Select all

            Reference< XDocumentInfoSupplier > xDocumentInfoSupplier(xComponent, UNO_QUERY);
            Reference< XDocumentInfo > xDocumentInfo = xDocumentInfoSupplier->getDocumentInfo();
            
            Reference< XDocumentPropertiesSupplier > xDocumentPropertiesSupplier(xDocumentInfo, UNO_QUERY);
            Reference< XDocumentProperties > xDocumentProperties = xDocumentPropertiesSupplier->getDocumentProperties();
            
            Reference< XPropertyContainer > xPropertyContainer = xDocumentProperties->getUserDefinedProperties();
            Reference< XPropertySet > xPropertySet(xPropertyContainer, UNO_QUERY);
        
            Reference< XPropertySetInfo > xPropertySetInfo = xPropertySet->getPropertySetInfo();
            
            if (xPropertySetInfo->hasPropertyByName(OUString::createFromAscii("Info 1")))
            {
                Any newValue, sName;
                newValue <<= OUString::createFromAscii("Value has been set by API");
                xPropertySet->setPropertyValue (OUString::createFromAscii("Info 1"), newValue);
            }
Firstly I would welcome any comments on the above code - is it correct or have I just been lucky?

Secondly please could I ask for advice as to whether it is best to keep this as a standalone utility and execute (spawn) it from the main application or would it be possible to build it into my application or better create a shared library? If so are there any guides / notes that I have missed for doing this?

The reason for asking is that the SDK clearly does a lot of the hard work, such as setting the appropriate environment variables, calling the cpp helper tools etc.

My application is wxWidgets based and I am currently using MinGW (Windows) and gcc / clang (Linux).

Thanks!

p.s. I really appreciate the effort to get the code snippets from oooforum.org back online. It has been something of a struggle for me to get this far and Google has teased me with some tantalizing links to oooforum that are no longer available :( .

Re: Setting Custom Properties from external application

Posted: Tue Aug 05, 2014 9:28 pm
by Villeroy
Open some ODF document with a zip tool and have a look at meta.xml which contains all the custom properties in plain simple XML. You don't need an over sophisticated office API to write custom properties into the meta.xml of an ODF document.

Re: Setting Custom Properties from external application

Posted: Tue Aug 05, 2014 9:46 pm
by iwbnwif
Villeroy, thank you for the fast response and good idea.

I will investigate this straight away.

However I would still be interested in the possibilities of using the API from an external application in case I later need to do something more exotic.

Re: Setting Custom Properties from external application

Posted: Tue Aug 05, 2014 9:52 pm
by Villeroy

Re: Setting Custom Properties from external application

Posted: Tue Aug 05, 2014 10:01 pm
by iwbnwif
Thanks again. Actually I used MRI to create the template code in my original post.

Sorry I wasn't clear about my (new) question. It is really more about compiling and linking, but I think I should first read:

https://wiki.openoffice.org/wiki/MakeFi ... me_example

To try to understand what the SDK does better.

Re: [Solved] Setting Custom Properties from external applica

Posted: Wed Aug 06, 2014 11:33 am
by iwbnwif
Open some ODF document with a zip tool and have a look at meta.xml which contains all the custom properties in plain simple XML. You don't need an over sophisticated office API to write custom properties into the meta.xml of an ODF document.
In fact this is excellent advice from Villeroy.

For reference I found by using the wxWidgets classes http://docs.wxwidgets.org/trunk/classwx ... ument.html and http://docs.wxwidgets.org/trunk/classwx ... tream.html make doing this a breeze :super: