Customize headers and footers.

Creating a macro - Writing a Script - Using the API

Customize headers and footers.

Postby Hs95 » Tue Dec 04, 2018 7:37 pm

Hi.
I'm using Java to operate on my file. I want to customize headers on each page or cutsomize style of each page. For example for page one set style first page, for page two,for, five set style default. It's possible or not ?
here is sample of my code

Code: Select all   Expand viewCollapse view
Object oDesktop = xOfficeFactory.createInstanceWithContext(
                  "com.sun.star.frame.Desktop", xOfficeComponentContext);
          XDesktop xDesktop = (XDesktop) UnoRuntime.queryInterface(
                  XDesktop.class, oDesktop);
          XComponent xCurrentComponent = xDesktop.getCurrentComponent();
          XModel xModel = (XModel) UnoRuntime.queryInterface(XModel.class, xCurrentComponent);

          XController xController = xModel.getCurrentController();
          XTextViewCursorSupplier xViewCursorSupplier =
                  (XTextViewCursorSupplier) UnoRuntime.queryInterface(
                          XTextViewCursorSupplier.class, xController);

          XTextViewCursor xViewCursor = xViewCursorSupplier.getViewCursor();
          XPropertySet xCursorPropertySet = (XPropertySet) UnoRuntime.queryInterface(
                  XPropertySet.class, xViewCursor);
          XPageCursor xPageCursor = (XPageCursor) UnoRuntime.queryInterface(
                  XPageCursor.class, xViewCursor);
          XText xDocumentText = xViewCursor.getText();
          com.sun.star.text.XTextCursor xTCursor = xDocumentText.createTextCursor();
          xPageCursor.jumpToFirstPage();
         
          XTextCursor xModelCursor = xDocumentText.createTextCursorByRange(xViewCursor.getStart());
          XParagraphCursor xParagraphCursor = (XParagraphCursor) UnoRuntime.queryInterface(
                  XParagraphCursor.class, xModelCursor);
          xParagraphCursor.gotoEndOfParagraph(false);
          xParagraphCursor.setString("Hello");
          XStorable xStorable = (XStorable) UnoRuntime.queryInterface(XStorable.class, xCurrentComponent);
          PropertyValue[] storeProps = new PropertyValue[1];
          storeProps[0] = new PropertyValue();
          storeProps[0].Name = "FilterName";
          storeProps[0].Value = "MS Word 97";
          XStyleFamiliesSupplier xStyleFamiliesSupplier = UnoRuntime.queryInterface(
                  XStyleFamiliesSupplier.class, xModel);
          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 xPageStyleProps = (XPropertySet) UnoRuntime.queryInterface(
                  XPropertySet.class, xStyle );
          xPageStyleProps.setPropertyValue("LeftMargin", new Short((short) 5000));
          xPageStyleProps.setPropertyValue("RightMargin", new Short((short) 5000));
          xPageStyleProps.setPropertyValue("TopMargin", new Short((short) 5000));
          xPageStyleProps.setPropertyValue("FooterIsOn", true);
          xPageStyleProps.setPropertyValue("HeaderIsOn", true);
//       
OpenOffice 3.1 on Windows Vista
Hs95
 
Posts: 7
Joined: Mon Dec 03, 2018 11:15 pm

Re: Customize headers and footers.

Postby Zizi64 » Tue Dec 04, 2018 8:00 pm

I suggest you: use a template file with preapared page styles instead of the java macro/program.
Tibor Kovacs, Hungary; LO6.1.6, 6.2.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-6.4.5;AOO4.1.7
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
User avatar
Zizi64
Volunteer
 
Posts: 9439
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Customize headers and footers.

Postby Hs95 » Tue Dec 04, 2018 9:39 pm

But i don't know how many pages i will have at my document
OpenOffice 3.1 on Windows Vista
Hs95
 
Posts: 7
Joined: Mon Dec 03, 2018 11:15 pm

Re: Customize headers and footers.

Postby Zizi64 » Tue Dec 04, 2018 9:57 pm

Code: Select all   Expand viewCollapse view
storeProps[0].Value = "MS Word 97";

Do not use foreign, osolete fileformats.
Last edited by Zizi64 on Tue Dec 04, 2018 9:58 pm, edited 1 time in total.
Tibor Kovacs, Hungary; LO6.1.6, 6.2.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-6.4.5;AOO4.1.7
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
User avatar
Zizi64
Volunteer
 
Posts: 9439
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Customize headers and footers.

Postby RoryOF » Tue Dec 04, 2018 9:57 pm

So read up on how to make headers/footers repeat from page to page. Details are in
[Tutorial] Page styles and headers/footers
Apache OpenOffice 4.1.7 on Xubuntu 18.04.4 (mostly 64 bit version) and very infrequently on Win2K/XP
User avatar
RoryOF
Moderator
 
Posts: 31239
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland


Return to Macros and UNO API

Who is online

Users browsing this forum: No registered users and 3 guests