[Solved] Add Header Footer using java code in OpenOffice

Discussions about using 3rd party extension with OpenOffice.org

[Solved] Add Header Footer using java code in OpenOffice

Postby Rushna » Tue Jul 18, 2017 9:02 am

Hi All,

I want to add header footer in current open document using Openoffice plugin.
there is XHeaderFooter class but I am not getting how it will work.

please help me out .. :(
Last edited by Rushna on Fri Sep 22, 2017 8:37 am, edited 1 time in total.
OpenOffice 4.3.1 on Windows 7
Rushna
 
Posts: 19
Joined: Tue May 09, 2017 12:42 pm

Re: Add Header Footer using java code in OpenOffice

Postby FJCC » Tue Jul 18, 2017 2:40 pm

I don't know Java but I recorded this using the MRI extension. I hope it helps.
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.container.NoSuchElementException;
import com.sun.star.container.XNameAccess;
import com.sun.star.container.XNameContainer;
import com.sun.star.lang.IllegalArgumentException;
import com.sun.star.lang.WrappedTargetException;
import com.sun.star.style.XStyle;
import com.sun.star.style.XStyleFamiliesSupplier;
import com.sun.star.uno.RuntimeException;
import com.sun.star.uno.UnoRuntime;
import com.sun.star.uno.XComponentContext;

public static void snippet(XComponentContext xComponentContext, Object oInitialTarget)
{
   try
   {
      XStyleFamiliesSupplier xStyleFamiliesSupplier = UnoRuntime.queryInterface(
         XStyleFamiliesSupplier.class, oInitialTarget);
      XNameAccess xNameAccess = xStyleFamiliesSupplier.getStyleFamilies();
      
      XNameContainer xNameContainer = UnoRuntime.queryInterface(
         XNameContainer.class, xNameAccess.getByName("PageStyles"));
      
      XNameAccess xNameAccess2 = UnoRuntime.queryInterface(
         XNameAccess.class, xNameContainer);
      XStyle xStyle = UnoRuntime.queryInterface(
         XStyle.class, xNameAccess2.getByName("Standard"));
      
      XPropertySet xPropSet = UnoRuntime.queryInterface(
         XPropertySet.class, xStyle);
      xPropSet.setPropertyValue("FooterIsOn", true);
      
   }
   catch (IllegalArgumentException e1)
   {
      // setPropertyValue
      e1.printStackTrace();
   }
   catch (PropertyVetoException e2)
   {
      // setPropertyValue
      e2.printStackTrace();
   }
   catch (WrappedTargetException e3)
   {
      // getByName, setPropertyValue
      e3.printStackTrace();
   }
   catch (UnknownPropertyException e4)
   {
      // setPropertyValue
      e4.printStackTrace();
   }
   catch (NoSuchElementException e5)
   {
      // getByName
      e5.printStackTrace();
   }
   catch (RuntimeException e6)
   {
      // getByName
      e6.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: 7091
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: Add Header Footer using java code in OpenOffice

Postby RoryOF » Tue Jul 18, 2017 5:56 pm

Here is a note on how to turn off Headers/Footers in OpenOffice using Java. Turning them on should be a simple change to the code.
https://stackoverflow.com/questions/37492362/openoffice-api-how-to-turn-off-headers-and-footers
Apache OpenOffice 4.1.6 on Xubuntu 18.04.2 (mostly 64 bit version) and very infrequently on Win2K/XP
User avatar
RoryOF
Moderator
 
Posts: 28567
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Add Header Footer using java code in OpenOffice

Postby Rushna » Wed Jul 19, 2017 8:43 am

I am looking for these two packages but I don't have idea how to implement.
Please suggest:

1) "com.sun.star.text.XHeaderFooter" and
2) "com.sun.star.text.XHeaderFooterPageStyle"
OpenOffice 4.3.1 on Windows 7
Rushna
 
Posts: 19
Joined: Tue May 09, 2017 12:42 pm

Re: Add Header Footer using java code in OpenOffice

Postby RoryOF » Wed Jul 19, 2017 9:23 am

Rushna wrote:I am looking for these two packages but I don't have idea how to implement.
Please suggest:

1) "com.sun.star.text.XHeaderFooter" and
2) "com.sun.star.text.XHeaderFooterPageStyle"


https://www.openoffice.org/api/docs/common/ref/com/sun/star/text/module-ix.html

Both now deprecated.

Your project - you must do the work.
Apache OpenOffice 4.1.6 on Xubuntu 18.04.2 (mostly 64 bit version) and very infrequently on Win2K/XP
User avatar
RoryOF
Moderator
 
Posts: 28567
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Add Header Footer using java code in OpenOffice

Postby UnklDonald418 » Wed Jul 19, 2017 8:00 pm

Have you look at Andrew Davison's book titled "Java LibreOffice Programming"?
http://fivedots.coe.psu.ac.th/~ad/jlop/
If your problem has been solved, please edit this topic's initial post and add "[Solved]" to the beginning of the subject line
Apache OpenOffice 4.1.6 & LibreOffice 6.1.5.2 - Windows 10 Professional
UnklDonald418
Volunteer
 
Posts: 1085
Joined: Wed Jun 24, 2015 12:56 am
Location: Colorado, USA

Re: Add Header Footer using java code in OpenOffice

Postby Rushna » Mon Aug 21, 2017 8:26 am

Added Header/Footer properly but Right/Left Header/Footer still not working.
I am using "HeaderTextRight" and "HeaderTextLeft".


please help...
OpenOffice 4.3.1 on Windows 7
Rushna
 
Posts: 19
Joined: Tue May 09, 2017 12:42 pm

Re: Add Header Footer using java code in OpenOffice

Postby Villeroy » Mon Aug 21, 2017 9:14 am

First you have to do it manually so you understand the concept of page styles. Then you may be able to do it programatically or drop this approach and work with templates.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04, OpenOffice 4.x & LibreOffice 6.x
User avatar
Villeroy
Volunteer
 
Posts: 26559
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Add Header Footer using java code in OpenOffice

Postby Rushna » Tue Aug 29, 2017 7:49 am

Hi..,
I am using this code but i am getting error in HeaderText.insertString(xTextCursor, s1, true); this line.look into this code and
please help me out.

TabStop[] tabStop=new TabStop[1];
tabStop[0]=new TabStop();
tabStop[0].Position=5001;
tabStop[0].Alignment=TabAlign.CENTER;


XTextCursor xTextCursor = (XTextCursor)UnoRuntime.queryInterface(XTextCursor.class,tabStop[0]);

XText HeaderText = (XText) UnoRuntime.queryInterface(XText.class, xStyleProps.getPropertyValue("HeaderText"));
HeaderText.insertString(xTextCursor, s1, true);
OpenOffice 4.3.1 on Windows 7
Rushna
 
Posts: 19
Joined: Tue May 09, 2017 12:42 pm

Re: Add Header Footer using java code in OpenOffice

Postby robleyd » Tue Aug 29, 2017 10:01 am

The actual error will help anyone trying to work out the problem.
Cheers
David
Apache OpenOffice 4.2.0 Build 9820 alpha version - Slackware 14.2 - 64 bit
LibreOffice 6.0.7.3 - Slackware 14.2 - 64 bit
Apache OpenOffice 4.1.4 - Windows 7 Virtual machine
User avatar
robleyd
Moderator
 
Posts: 2570
Joined: Mon Aug 19, 2013 3:47 am
Location: Murbko, Australia


Return to Extensions

Who is online

Users browsing this forum: No registered users and 2 guests