Replace using regular expressions

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
carlos.lima
Posts: 4
Joined: Tue Jul 10, 2018 3:18 pm

Replace using regular expressions

Post by carlos.lima »

Hi there,

I have tried replacing all paragraphs in my writer file with the following code:

Code: Select all

XReplaceable xReplaceable = UnoRuntime.queryInterface(XReplaceable.class, document);
                XReplaceDescriptor xRepDesc = xReplaceable.createReplaceDescriptor();

                xRepDesc.setSearchString("$");
                xRepDesc.setReplaceString("");

                PropertyValue[] aReplaceArgs = new PropertyValue[1];

                aReplaceArgs[0] = new PropertyValue();
                aReplaceArgs[0].Name = "SearchRegularExpression";
                aReplaceArgs[0].Value = true;

                XPropertyReplace xPropRepl = UnoRuntime.queryInterface(XPropertyReplace.class, xRepDesc);
                xPropRepl.setReplaceAttributes(aReplaceArgs);

                // replace
                long nResult = xReplaceable.replaceAll(xRepDesc);
But, I didn't understand this error:

Code: Select all

com.sun.star.beans.UnknownPropertyException: 
	at com.sun.star.lib.uno.environments.remote.Job.remoteUnoRequestRaisedException(Job.java:177)
	at com.sun.star.lib.uno.environments.remote.Job.execute(Job.java:143)
	at com.sun.star.lib.uno.environments.remote.JobQueue.enter(JobQueue.java:335)
	at com.sun.star.lib.uno.environments.remote.JobQueue.enter(JobQueue.java:304)
	at com.sun.star.lib.uno.environments.remote.JavaThreadPool.enter(JavaThreadPool.java:91)
	at com.sun.star.lib.uno.bridges.java_remote.java_remote_bridge.sendRequest(java_remote_bridge.java:639)
	at com.sun.star.lib.uno.bridges.java_remote.ProxyFactory$Handler.request(ProxyFactory.java:151)
	at com.sun.star.lib.uno.bridges.java_remote.ProxyFactory$Handler.invoke(ProxyFactory.java:133)
	at com.sun.proxy.$Proxy67.setReplaceAttributes(Unknown Source)
OpenOffice 3.1 on Windows Vista
carlos.lima
Posts: 4
Joined: Tue Jul 10, 2018 3:18 pm

Re: Replace using regular expressions

Post by carlos.lima »

I followed the link https://wiki.openoffice.org/wiki/Docume ... nd_Replace on Open Office documentation
OpenOffice 3.1 on Windows Vista
Post Reply