Help Needed to on/off track change word document using Java

Java, C++, C#, Delphi, ??? - Using the UNO bridges

Help Needed to on/off track change word document using Java

Postby 399192 » Fri Oct 17, 2014 8:29 am

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
OpenOffice 2.3 on Windows 7
399192
 
Posts: 2
Joined: Fri Oct 17, 2014 8:17 am

Re: Help Needed to on/off track change word document using J

Postby FJCC » Fri Oct 17, 2014 2:42 pm

There is a RecordChanges property at the top level of the document. In Basic one would write
Code: Select all   Expand viewCollapse view
ThisComponent.RecordChange = True

Using the MRI extension I recorded this Java code
Code: Select all   Expand viewCollapse view
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();
   }
}
Windows 10 and Linux Mint, since 2017
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
FJCC
Moderator
 
Posts: 7682
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: Help Needed to on/off track change word document using J

Postby 399192 » Tue Oct 21, 2014 12:05 pm

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   Expand viewCollapse view
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
399192
 
Posts: 2
Joined: Fri Oct 17, 2014 8:17 am


Return to External Programs

Who is online

Users browsing this forum: No registered users and 5 guests