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
Help Needed to on/off track change word document using Java
Help Needed to on/off track change word document using Java
OpenOffice 2.3 on Windows 7
Re: Help Needed to on/off track change word document using J
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
ThisComponent.RecordChange = True
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();
}
}
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.
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
Re: Help Needed to on/off track change word document using J
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 --
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);
OpenOffice 2.3 on Windows 7