[Solved] Add Header Footer using java code in OpenOffice
[Solved] Add Header Footer using java code in OpenOffice
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 ..
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
Re: Add Header Footer using java code in OpenOffice
I don't know Java but I recorded this using the MRI extension. I hope it helps.
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.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();
}
}
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: Add Header Footer using java code in OpenOffice
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/374 ... nd-footers
https://stackoverflow.com/questions/374 ... nd-footers
Apache OpenOffice 4.1.15 on Xubuntu 22.04.4 LTS
Re: Add Header Footer using java code in OpenOffice
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"
Please suggest:
1) "com.sun.star.text.XHeaderFooter" and
2) "com.sun.star.text.XHeaderFooterPageStyle"
OpenOffice 4.3.1 on Windows 7
Re: Add Header Footer using java code in OpenOffice
https://www.openoffice.org/api/docs/com ... le-ix.htmlRushna 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"
Both now deprecated.
Your project - you must do the work.
Apache OpenOffice 4.1.15 on Xubuntu 22.04.4 LTS
-
- Volunteer
- Posts: 1549
- Joined: Wed Jun 24, 2015 12:56 am
- Location: Colorado, USA
Re: Add Header Footer using java code in OpenOffice
Have you look at Andrew Davison's book titled "Java LibreOffice Programming"?
http://fivedots.coe.psu.ac.th/~ad/jlop/
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.14 & LibreOffice 7.6.2.1 (x86_64) - Windows 10 Professional- Windows 11
Apache OpenOffice 4.1.14 & LibreOffice 7.6.2.1 (x86_64) - Windows 10 Professional- Windows 11
Re: Add Header Footer using java code in OpenOffice
Added Header/Footer properly but Right/Left Header/Footer still not working.
I am using "HeaderTextRight" and "HeaderTextLeft".
please help...
I am using "HeaderTextRight" and "HeaderTextLeft".
please help...
OpenOffice 4.3.1 on Windows 7
Re: Add Header Footer using java code in OpenOffice
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 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Re: Add Header Footer using java code in OpenOffice
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);
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
Re: Add Header Footer using java code in OpenOffice
The actual error will help anyone trying to work out the problem.
Cheers
David
OS - Slackware 15 64 bit
Apache OpenOffice 4.1.15
LibreOffice 24.2.2.2; SlackBuild for 24.2.2 by Eric Hameleers
David
OS - Slackware 15 64 bit
Apache OpenOffice 4.1.15
LibreOffice 24.2.2.2; SlackBuild for 24.2.2 by Eric Hameleers