Pyuno: Headers

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
imr_lor
Posts: 23
Joined: Fri Sep 04, 2015 10:28 am

Pyuno: Headers

Post by imr_lor »

I need to implement a header Program wise which has to start at
an Specific Page on the Document and needs to go on over the rest of the document.
This needs to be done by the program.
Im using Python for this.
I found something but it seem like it is not implemented in Pyuno.
Any help?
Last edited by imr_lor on Tue Oct 27, 2015 11:12 am, edited 5 times in total.
OpenOffice 3.1 on LinuxMint 17.1
FJCC
Moderator
Posts: 9624
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: Pyuno

Post by FJCC »

Here is the beginning of doing this. I created a page style and added it to the document but it would be better if a style already existed.

Code: Select all

from com.sun.star.style.BreakType import PAGE_BEFORE

def AddHeaderAtPageThree():
    oDoc = XSCRIPTCONTEXT.getDocument()
    StyleFam = oDoc.StyleFamilies
    PageStyles = StyleFam.getByName("PageStyles")

    NewStyle = oDoc.createInstance("com.sun.star.style.PageStyle")
    PageStyles.insertByName("MyNewStyle", NewStyle)

    NewStyle.HeaderIsOn = True
    NewStyle.HeaderText.String = "The New Header Text"

    oVC = oDoc.CurrentController.ViewCursor
    oVC.jumpToPage(3)
    oVC.BreakType = PAGE_BEFORE
    oVC.PageDescName = "MyNewStyle"
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.
imr_lor
Posts: 23
Joined: Fri Sep 04, 2015 10:28 am

Re: Pyuno: Headers

Post by imr_lor »

Thank you very much. I have two questions left:
I already have an page Style so how can I modify it?
How can I import XSCRIPTCONTEXT?
OpenOffice 3.1 on LinuxMint 17.1
User avatar
karolus
Volunteer
Posts: 1243
Joined: Sat Jul 02, 2011 9:47 am

Re: Pyuno: Headers

Post by karolus »

imr_lor wrote: How can I import XSCRIPTCONTEXT?
You cannot import it, because its a global Variable in Python if you run it through|from inside soffice.

If your running python independetly from soffice, you need first some other preparations to connect the soffice-process:

Code: Select all

####_server.py this Script runs sOffice in Pipe-mode with an pipe named `abraxas`
from subprocess import Popen

officepath = 'soffice'
pipe = "--accept=pipe,name=abraxas;urp;StarOffice.Servicemanager"


Popen([officepath,  pipe])
 
, after all something like:

Code: Select all

#
import uno
from pythonscript import ScriptContext

local = uno.getComponentContext()
resolver = local.ServiceManager.createInstance("com.sun.star.bridge.UnoUrlResolver")

client = resolver.resolve("uno:pipe,"
                           "name=abraxas;"
                           "urp;"
                           "StarOffice.ComponentContext")

XSCRIPTCONTEXT = ScriptContext(client, None, None) 
should bind XSCRIPTCONTEXT to roughly the same Object as used from inside sOffice_python
Libreoffice 25.2… on Debian 13 (trixie) (on RaspberryPI5)
Libreoffice 25.8… flatpak on Debian 13 (trixie) (on RaspberryPI5)
imr_lor
Posts: 23
Joined: Fri Sep 04, 2015 10:28 am

Re: Pyuno: Headers

Post by imr_lor »

I have some Problems importing

Code: Select all

from pythonscript import ScriptContext
it returns the error ImportError: No module named 'pythonscript' (or 'pythonscript.ScriptContext' is unknown)

Update:
I found this( https://docs.libreoffice.org/scripting/ ... ource.html ) but i dont know how to implement it
OpenOffice 3.1 on LinuxMint 17.1
User avatar
karolus
Volunteer
Posts: 1243
Joined: Sat Jul 02, 2011 9:47 am

Re: Pyuno: Headers

Post by karolus »

Hallo

Actually we have a problem: we know nothing about your Environment, and (it seems) you know less than that :?

Your Signatur states: OO3.1 @ Linux Mint 17.1

Really that outdated Version of OpenOffice on an almost actual 17.1

Linux Mint 17.1 normally comes out of the box with LibreOffice 4.x, but unfortuneatly without pythonscript ( in this case search for libreoffice-script-provider-python in your Package-manager and install it.)
Libreoffice 25.2… on Debian 13 (trixie) (on RaspberryPI5)
Libreoffice 25.8… flatpak on Debian 13 (trixie) (on RaspberryPI5)
imr_lor
Posts: 23
Joined: Fri Sep 04, 2015 10:28 am

Re: Pyuno: Headers

Post by imr_lor »

Ok I managed to implement it and it works. Thanks so far.
How do I applie this for an certain Page Style(which is already defined) in the whole document(and the header needs to be centered)?
OpenOffice 3.1 on LinuxMint 17.1
User avatar
Villeroy
Volunteer
Posts: 31363
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Pyuno: Headers

Post by Villeroy »

You open your document template for editing and change the page style. Why all this macro bullshit for the most trivial tasks?
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
imr_lor
Posts: 23
Joined: Fri Sep 04, 2015 10:28 am

Re: Pyuno: Headers

Post by imr_lor »

karolus wrote:Hallo

Actually we have a problem: we know nothing about your Environment, and (it seems) you know less than that :?

Your Signatur states: OO3.1 @ Linux Mint 17.1

Really that outdated Version of OpenOffice on an almost actual 17.1

Linux Mint 17.1 normally comes out of the box with LibreOffice 4.x, but unfortuneatly without pythonscript ( in this case search for libreoffice-script-provider-python in your Package-manager and install it.)
Im working on Linux Mint 17.1 with LibreOffice 4.2.8.2
Im using Python 3.4.0.
This Project wasnt originally programmed by me but I have to update it and to implement various new functions.
The main Problem is that this Programm is poorly documented :ucrazy: and I never worked with the Libre/Openoffice API before.
But after implementing those Headers I can finally move on to an new Project.
So thank you for understanding that im not very into programming with UNO.
OpenOffice 3.1 on LinuxMint 17.1
imr_lor
Posts: 23
Joined: Fri Sep 04, 2015 10:28 am

Re: Pyuno: Headers

Post by imr_lor »

Villeroy wrote:You open your document template for editing and change the page style. Why all this macro bullshit for the most trivial tasks?
Firstival as mentioned in a Post viewtopic.php?f=20&t=79728before This is not a makro!
And the other reason is that this programm processes given Information into an document.
OpenOffice 3.1 on LinuxMint 17.1
User avatar
Villeroy
Volunteer
Posts: 31363
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Pyuno: Headers

Post by Villeroy »

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
imr_lor
Posts: 23
Joined: Fri Sep 04, 2015 10:28 am

Re: Pyuno: Headers

Post by imr_lor »

Seems interesting but its definitely not the thing I am looking for.
As mentioned above the only thing i still need to do is to apply this header to all pages of a certain pagestyle.
OpenOffice 3.1 on LinuxMint 17.1
Post Reply