| View previous topic :: View next topic |
| Author |
Message |
christopher23 General User

Joined: 25 Feb 2010 Posts: 19
|
Posted: Thu Mar 25, 2010 5:32 am Post subject: create new header for each page |
|
|
I would like to create a new header for each page with different text in it. But I also use page numbering in the footer so this needs to stay in tact. Is this possible?
I'm working with PyUNO and Python to create this word document. the piece for creating the header is pasted below:
| Code: |
pageStyleCollection = document.getStyleFamilies().getByName("PageStyles")
propertySet = pageStyleCollection.getByName("Standard")
# Call interface to the text of the Header
propertySet.setPropertyValue("HeaderIsOn", True)
headerText = propertySet.getPropertyValue("HeaderText")
headerLogo = headerText.createTextCursor()
# Create GraphicObject to hold our Image
graphicObject = document.createInstance("com.sun.star.text.GraphicObject")
# Load External image into Word Document
graphicObject.setPropertyValue("GraphicURL", operator.loadGraphicIntoDocument(document, "C:/logo.png", "BekenT Logo"))
# Determine Width and Height
graphicObject.setPropertyValue("Width", 4000)
graphicObject.setPropertyValue("Height", 1380)
# Anchortype and Align to the right
graphicObject.setPropertyValue("AnchorType", AT_PARAGRAPH)
graphicObject.setPropertyValue("HoriOrient", 1)
graphicObject.setPropertyValue("VertOrient", 1)
# Add image to Header
headerText.insertTextContent(headerLogo, graphicObject, False)
text = headerText.Text
cursor = text.createTextCursor()
cursor.setPropertyValue("ParaStyleName", "Heading 1")
cursor.setPropertyValue("ParaBottomMargin", 50)
cursor.setPropertyValue("CharFontName", "Arial")
cursor.setPropertyValue("CharHeight", 10)
cursor.setPropertyValue("CharWeight", BOLD)
cursor.setPropertyValue("CharColor", operator.getCharColor("61116a"))
text.insertString(cursor, "%s Adwords Campagne Rapportage" % acctname, 0) |
But this code creates the same header for all pages. So this is something that needs to be changed.
Examples of Java and Basic are also welcome. I just need some examples on how this can be done. |
|
| Back to top |
|
 |
christopher23 General User

Joined: 25 Feb 2010 Posts: 19
|
Posted: Fri Mar 26, 2010 6:14 am Post subject: |
|
|
what I figured out so far is that to create a new header I need to create a new PageStyle.
| Code: | # Get all StyleFamilies
pageStyleCollection = document.getStyleFamilies().getByName("PageStyles")
# Creating new style
newStyle = document.createInstance("com.sun.star.style.PageStyle")
# Adding the new style to pagestyle family
pageStyleCollection.insertByName("CampaignStyle", newStyle)
# Access the "CampaignStyle" pagestyle
propertySet = pageStyleCollection.getByName("CampaignStyle")
# Call interface to the text of the Header
propertySet.setPropertyValue("HeaderIsOn", True)
headerText = propertySet.getPropertyValue("HeaderText")
header_text = headerText.Text
cursor = header_text.createTextCursor()
header_text.insertString(cursor, "Adwords Campagne Rapportage", 0) |
But this doesn't seem to work either. Am I doing something wrong here?
I'm creating a new style using that newly created style and adding text to the header of that style. |
|
| Back to top |
|
 |
hanya Super User

Joined: 04 May 2005 Posts: 543 Location: Japan
|
Posted: Fri Mar 26, 2010 7:33 am Post subject: |
|
|
Set FollowStyle property of your page styles.
| Code: | Sub PageStyleForEachPage
oDoc = ThisComponent
oText = oDoc.getText()
oPageStyles = oDoc.getStyleFamilies().getByName("PageStyles")
' for page 1
oStyle = oDoc.createInstance("com.sun.star.style.PageStyle")
oPageStyles.insertByName("NewStyle_1", oStyle)
oStyle.HeaderIsOn = True
oStyle.HeaderText.setString("Page 1")
' for page 2
oStyle = oDoc.createInstance("com.sun.star.style.PageStyle")
oPageStyles.insertByName("NewStyle_2", oStyle)
oStyle.HeaderIsOn = True
oStyle.HeaderText.setString("Page 2")
' follower style
oPageStyles.getByName("NewStyle_1").FollowStyle = "NewStyle_2"
' write something
oViewCursor = oDoc.getCurrentController().getViewCursor()
oCursor = oText.createTextCursor()
oCursor.setString("page ?")
oViewCursor.gotoRange(oCursor, False)
oCursor.PageDescName = "NewStyle_1"
oViewCursor.jumpToEndOfPage()
oViewCursor.BreakType = com.sun.star.style.BreakType.PAGE_AFTER
oCursor = oText.createTextCursorByRange(oViewCursor)
oCursor.setString(Chr(13) & "new page")
End Sub |
|
|
| Back to top |
|
 |
christopher23 General User

Joined: 25 Feb 2010 Posts: 19
|
Posted: Tue Mar 30, 2010 1:11 am Post subject: |
|
|
thanks hanya,
it seems to work however my page numbering in the footer has disappeared .. is their some way of changing only the header and leaving the footer unchanged? |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|