Make selection with ViewCursor for Text in Footer\Header

This clipped code:

oTextCursor.goToRange(oPor.getStart(), False) 
oViewCursor.goToRange(oTextCursor, False)
oTextCursor.goToRange(oPor.getEnd(), False) 
oViewCursor.goToRange(oTextCursor, True)

select text portion (oPor) if oTextCursor was created in document body (ThisComponent.Text) and oPor is his paragraphs or text portions, but if oTextCursor and oViewCursor was created in this way:

oPageStyle = ThisComponent.getStyleFamilies.getByName("PageStyles").getByName(oPageStyleName)
REM In thi place - enumeration of paragraphs and textPortions(oPor) in oPageStyle.FooterText.Text
oTextCursor = oPageStyle.FooterText.Text.CreateTextCursor()
oViewCursor = ThisComponent.CurrentController.getViewCursor()
oTextCursor.goToRange(oPor.getStart(), False) 
oViewCursor.goToRange(oTextCursor, False)
oTextCursor.goToRange(oPor.getEnd(), False) 
oViewCursor.goToRange(oTextCursor, True) <----

, then text selection failed.

How to select text portion in Footer or Header?

For example what to select oTextCursor directly without ViewCursor?

	oTextCursor=oPageStyle.FooterText.Text.CreateTextCursor()
	oTextCursor.goToEnd(true)
	oDoc.CurrentController.Select(oTextCursor)

Absolutly no effects. Even the cursor doesn’t move.

Test this, in my example it is functional.

Sub selectHeaderText
	dim oDoc as object, oStyles as object, oStyle as object, oCur as object
	oDoc=ThisComponent
	oStyles=oDoc.StyleFamilies.getByName("PageStyles")
	oStyle=oStyles.getByName(oDoc.CurrentController.ViewCursor.PageStyleName) 'get actual page PageStyle
	oCur=oStyle.HeaderText.createTextCursor
	'oCur=oStyle.FooterText.createTextCursor
	oCur.goRight(10, true)
	oDoc.CurrentController.Select(oCur)
End Sub

selectHeaderText.odt (14.6 kB)

2 Likes

This works great! Thanks!

However, as it turned out, my version is also working. BUT! only if same content on left and right pages and same content on first page are enabled in the page style properties. If these options are disabled, no text will be selected (Or it will be selected not on the current, but on the previous page (it seems there is a correspondence between the left page and the normal page)). This was my problem.

Thus, if the document uses left and right pages or a special footer \ header for the first page, the selection should be made in FooterTextFirst, FooterTextLeft and FooterTextRight. As a result, FooterText is the text in the footer when not a special first or left/right page.

Thank you very much for your help!
P.S. I wish you a quick, easy recovery! :slight_smile: