Page 1 of 1
Pyuno: Headers
Posted: Fri Oct 23, 2015 9:20 am
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?
Re: Pyuno
Posted: Sat Oct 24, 2015 5:08 am
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"
Re: Pyuno: Headers
Posted: Mon Oct 26, 2015 10:09 am
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?
Re: Pyuno: Headers
Posted: Mon Oct 26, 2015 12:39 pm
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
Re: Pyuno: Headers
Posted: Tue Oct 27, 2015 10:52 am
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
Re: Pyuno: Headers
Posted: Tue Oct 27, 2015 12:33 pm
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.)
Re: Pyuno: Headers
Posted: Tue Oct 27, 2015 1:25 pm
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)?
Re: Pyuno: Headers
Posted: Tue Oct 27, 2015 1:33 pm
by Villeroy
You open your document template for editing and change the page style. Why all this macro bullshit for the most trivial tasks?
Re: Pyuno: Headers
Posted: Tue Oct 27, 2015 1:35 pm
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

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.
Re: Pyuno: Headers
Posted: Tue Oct 27, 2015 1:38 pm
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.
Re: Pyuno: Headers
Posted: Tue Oct 27, 2015 2:19 pm
by Villeroy
Re: Pyuno: Headers
Posted: Tue Oct 27, 2015 2:22 pm
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.