Page 1 of 1
Help Needed to on/off track change word document using Java
Posted: Fri Oct 17, 2014 8:29 am
by 399192
Hi,
In our java application open office 2.3 is used to generate/upload word document. I am trying to generate the word document on Track change mode on during generation. Is there any property or attribute that can be set using java code to achive?
Thanks,
Roy
Re: Help Needed to on/off track change word document using J
Posted: Fri Oct 17, 2014 2:42 pm
by FJCC
There is a RecordChanges property at the top level of the document. In Basic one would write
Using the MRI extension I recorded this Java code
Code: Select all
import com.sun.star.beans.PropertyVetoException;
import com.sun.star.beans.UnknownPropertyException;
import com.sun.star.beans.XPropertySet;
import com.sun.star.lang.IllegalArgumentException;
import com.sun.star.lang.WrappedTargetException;
import com.sun.star.uno.UnoRuntime;
import com.sun.star.uno.XComponentContext;
public static void snippet(XComponentContext xComponentContext, Object oInitialTarget)
{
try
{
XPropertySet xPropSet = UnoRuntime.queryInterface(
XPropertySet.class, oInitialTarget);
xPropSet.setPropertyValue("RecordChanges", true);
}
catch (WrappedTargetException e1)
{
// setPropertyValue
e1.printStackTrace();
}
catch (PropertyVetoException e2)
{
// setPropertyValue
e2.printStackTrace();
}
catch (IllegalArgumentException e3)
{
// setPropertyValue
e3.printStackTrace();
}
catch (UnknownPropertyException e4)
{
// setPropertyValue
e4.printStackTrace();
}
}
Re: Help Needed to on/off track change word document using J
Posted: Tue Oct 21, 2014 12:05 pm
by 399192
Hi FJCC, thanks for you respond. I am getting the Unknown property Exception. Please note I am using version 2.3 which is pretty old version.
com.sun.star.beans.UnknownPropertyException: unknown property RecordChanges
Code snippet --
Code: Select all
XComponentContext xcomponentcontext = null;
try {
xcomponentcontext = Bootstrap.createInitialComponentContext( null );
} catch (com.sun.star.uno.Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (java.lang.Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
XMultiComponentFactory xmulticomponentfactory =
xcomponentcontext.getServiceManager();
Object objectUrlResolver = null;
try {
objectUrlResolver = xmulticomponentfactory.createInstanceWithContext(
"com.sun.star.bridge.UnoUrlResolver", xcomponentcontext );
} catch (com.sun.star.uno.Exception e) {
logException("Unable to create Instance With Context", e);
}
// Create a new url resolver
XUnoUrlResolver xurlresolver = ( XUnoUrlResolver )
UnoRuntime.queryInterface( XUnoUrlResolver.class,
objectUrlResolver );
Object objectInitial = null;
try {
objectInitial = xurlresolver.resolve(pURL);
} catch (NoConnectException e) {
logException("URL Resolver.resolve -" + pURL, e);
} catch (ConnectionSetupException e) {
logException("URL Resolver.resolve -" + pURL, e);
} catch (IllegalArgumentException e) {
logException("URL Resolver.resolve -" + pURL, e);
}
// Create a service manager from the initial object
xmulticomponentfactory = ( XMultiComponentFactory )
UnoRuntime.queryInterface( XMultiComponentFactory.class, objectInitial );
// Query for the XPropertySet interface.
XPropertySet xpropertysetMultiComponentFactory = ( XPropertySet )
UnoRuntime.queryInterface( XPropertySet.class, xmulticomponentfactory );
// Get the default context from the office server.
Object objectDefaultContext = null;
try {
try {
xpropertysetMultiComponentFactory.setPropertyValue("RecordChanges", true);