Customize headers and footers.

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
Hs95
Posts: 7
Joined: Mon Dec 03, 2018 11:15 pm

Customize headers and footers.

Post by Hs95 »

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

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
User avatar
Zizi64
Volunteer
Posts: 11362
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Customize headers and footers.

Post by Zizi64 »

I suggest you: use a template file with preapared page styles instead of the java macro/program.
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
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.
Hs95
Posts: 7
Joined: Mon Dec 03, 2018 11:15 pm

Re: Customize headers and footers.

Post by Hs95 »

But i don't know how many pages i will have at my document
OpenOffice 3.1 on Windows Vista
User avatar
Zizi64
Volunteer
Posts: 11362
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Customize headers and footers.

Post by Zizi64 »

Code: Select all

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; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
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
RoryOF
Moderator
Posts: 34618
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Customize headers and footers.

Post by RoryOF »

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.15 on Xubuntu 22.04.4 LTS
Post Reply