
Sub kopftexte
	oDoc=Thiscomponent
	'lösche alle alten Kopfrahmen
	oFrames=odoc.getTextFrames()
	for i=oframes.count-1 to 0 step -1
		if left(oFrames.getbyindex(i).name,10)="Kopfrahmen" then 'lösche alten Rahmen
			oDoc.Text.removeTextContent(oFrames.getbyindex(i))
		end if
	next
	'öffne Calc
	sUrl=Thiscomponent.getUrl()
	for k=1 to len(sUrl)
		if mid(sUrl,k,1)="/" then slash=k
		if mid(sUrl,k,1)="." then punkt=k
	next k
	sPfad=left(sUrl,slash)
	sCalc=sPfad & "Kopfzeilen_Texte_Breit.ods"
	Dim myFileProp() as new com.sun.star.beans.PropertyValue
	oCalcDoc = StarDesktop.loadComponentFromURL(sCalc, "_blank", 0, myFileProp() )
	'Auslesen der Informationen
	aTexte=oCalcDoc.Sheets(0).getCellRangeByname("A2:D100").getDataArray
	oCalcDoc.Close(false)
	oView=oDoc.getcurrentcontroller().getviewcursor()
	'gehe zur ersten Seite
	oView.jumptofirstpage()
	' Vorbereitung Tabulator im Textrahmen
	Dim tab(0) As New com.sun.star.style.TabStop
	tab(0).Alignment = com.sun.star.style.TabAlign.RIGHT
	'Linienstil für Textrahmen
	Dim oLinie0 as New com.sun.star.table.BorderLine
	Dim oLinie1 as New com.sun.star.table.BorderLine
	oLinie0.innerLineWidth=0
	oLinie0.outerLineWidth=0
	'Ermittlung des Seitenformats
	formatname=oView.PageDescName
	StyleFamilies = oDoc.StyleFamilies
    PageStyles = StyleFamilies.getByName("PageStyles")
    if isempty(formatname) then     
	    PageFormat = PageStyles.getByName("Standard")
	  else
	    PageFormat = PageStyles.getByName(formatname)
	end if
	'Ermittlung der Seitenbreite und -ränder
	s_breite=PageFormat.width
	randl=PageFormat.Leftmargin
	randr=PageFormat.rightmargin
	oView.jumptolastpage()
	'Anzahl der Seiten?
	n=oDoc.getcurrentcontroller().pageCount
	z=0	'Zähler für aktuelles Kopftextepaar
	'Durchlauf durch alle Seiten
	for i=1 to n
		'erzeuge textrahmen
		oFrame = oDoc.createInstance("com.sun.star.text.TextFrame")
		with oFrame
			.name="Kopfrahmen" & i
			.width = s_breite-randl-randr
			.height=500	'Hier wird die Höhe der Textfelder festgelegt 500=5mm
			.AnchorType = com.sun.star.text.TextContentAnchorType.AT_PAGE
			.HoriOrient=0
			.HoriOrientrelation=7
			.HoriOrientPosition =randl	'wie linker Rand
			.VertOrient=0
			.VertOrientRelation=7
			.VertOrientPosition = 300	'Position von oben: 3 mm
			'Umrandung
			.rightBorder=oLinie0
			.leftBorder=oLinie0
			.topBorder=oLinie0
			.bottomBorder=oLinie0
			.LeftBorderDistance=0
			.RightBorderDistance=0
			.Surround=com.sun.star.text.WrapTextMode.THROUGH
		end with
		oDoc.Text.insertTextContent(oview, oFrame, FALSE) 'oTextC
		'setze Anker auf richtige Seite
		oFrame.AnchorPageNo=i
		'Schreibe Text in Rahmen
		oFrameCursor=oFrame.createTextCursor()
		oFrameCursor.ParaStyleName="_Gl_Kopf-8-links"
		If int(i/2)=i/2 Then 'linke Seite
			oFrameCursor.ParaStyleName="_Gl_Kopf-8-rechts"
		End If
		If i=1 or i=n Then
			oFrameCursor.ParaStyleName="_Gl_Kopf-8-zentriert"
		End If
		'Text aus Calctabelle entnehmen
		If i>aTexte(z)(2) then z=z+1
		If int(i/2)=i/2 Then 'gerade Seite
			sKopf=aTexte(z)(0)
		Else
			sKopf=aTexte(z)(3)
		End If
		oFrameCursor.String=sKopf
	Next
End Sub
