Tabelle einfügen

Programmierung unter AOO/LO (StarBasic, Python, Java, ...)

Moderator: Moderatoren

mike6
*****
Beiträge: 479
Registriert: Sa, 06.03.2004 13:58

Tabelle einfügen

Beitrag von mike6 »

Hallo,

ich habe mir ein Makro geschrieben, dass eine fertige Tabelle in ein Writer Dokument einfügt.

Code: Alles auswählen

Sub Tabelle_Abstimmung_einfuegen
	Dim oDoc as Object
	Dim oText as Object
	Dim oTextCursor as Object

	' hole das aktuelle Dokument (OOoWriter)
	oDoc = ThisComponent

	' hole den Text-Inhalt des Dokumentes
	oText = oDoc.Text

	' hole den Text Cursor
	oTextCursor = oText.Text.createTextCursor()
	oTextCursor.gotoRange(oDoc.GetCurrentController.ViewCursor, False)

	' einen Titel einfügen
	oText.insertString( oTextCursor, "" , false)
	' Format zuweisen individuell /
	'oTextCursor.gotoEnd(true)
	'oTextCursor.CharColor = RGB(0, 0, 0) 
	'oTextCursor.CharFontName ="Tahoma"
 	'oTextCursor.CharHeight =14
		
	' oder als Vorlage
    oTextCursor.ParaStyleName = "Tabelle Abstimmung"
 
	' Zeilenumbruch
	oText.insertControlCharacter( oTextCursor,com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK, FALSE )

	' erzeuge eine TextTabelle
	oTextTable = oDoc.createInstance( "com.sun.star.text.TextTable" )

 	' mit 4 Zeilen und 2 Spalten
 	oTextTable.initialize( 4,2 )
 	
 	' TextTabelle ins Dokument einfügen
 	oText.insertTextContent( oTextCursor, oTextTable, FALSE)
 	 	
 	' Zelle 0,0: Text einsetzen und formatieren 
 	oTextTable.getCellByPosition(0,0).String = "Abstimmungsergebnis:"

 	' TextCursor in Zelle 0,0
 	oTextCursor = oTextTable.getCellByPosition(0,0).createTextCursor()

 	' Format zuweisen individuell 
 	'oTextCursor.gotoEnd(true)
	'oTextCursor.CharColor = RGB(0, 0, 0) 
	'oTextCursor.CharFontName ="Tahoma"
 	'oTextCursor.CharHeight =10
		
	' oder als Vorlage
    oTextCursor.ParaStyleName = "Tabelle Abstimmung"

	' zentrieren
	oTextCursor.ParaAdjust = com.sun.star.style.ParagraphAdjust.CENTER	

 	' Kopfzelle mit grauem Hintergrund
 	' oTextTable.getCellByPosition(1,0).BackColor = RGB( 200,200,200 )
 	 	

 	' Zelle 1,0: Text einsetzen und formatieren 
 	oTextTable.getCellByPosition(1,0).String = ""

 	

 	' TextCursor in Zelle 1,0
 	oTextCursor = oTextTable.getCellByPosition(1,0).createTextCursor()

 	
 	' Format zuweisen individuell 
 	'oTextCursor.gotoEnd(true)
	'oTextCursor.CharColor = RGB(0, 0, 0) 
	'oTextCursor.CharFontName ="Tahoma"
 	'oTextCursor.CharHeight =10
 	
 	
    ' oder als Vorlage
    oTextCursor.ParaStyleName = "Tabelle Abstimmung"
 	

	' zentrieren
	oTextCursor.ParaAdjust = com.sun.star.style.ParagraphAdjust.CENTER

 	' Zelle 0,1: Text einsetzen
 	oTextTable.getCellByPosition(0,1).String = "" 	

 	' Zelle 1,1: Wert einsetzen 
 	oTextTable.getCellByPosition(1,1).String = "5 Ja-Stimmen" 	

 	' Zelle 0,2: Text einsetzen
 	oTextTable.getCellByPosition(0,2).String = "" 	

 	' Zelle 1,2: Wert einsetzen 
 	oTextTable.getCellByPosition(1,2).String = "0 Nein-Stimmen" 
 	
 	' Zelle 0,3: Text einsetzen
 	oTextTable.getCellByPosition(0,3).String = "" 	

 	' Zelle 1,3: Text einsetzen 
 	oTextTable.getCellByPosition(1,3).String = "0 Enthaltungen "
 			

 	' TextCursor in Zelle 1,1
 	oTextCursor = oTextTable.getCellByPosition(1,1).createTextCursor()
   
 	' Format zuweisen individuell 
 	'oTextCursor.gotoEnd(true)
	'oTextCursor.CharColor = RGB(0, 0, 0) 
	'oTextCursor.CharFontName ="Tahoma"
 	'oTextCursor.CharHeight =10
 		
	' oder als Vorlage
    oTextCursor.ParaStyleName = "Tabelle Abstimmung"
	
		
	' TextCursor in Zelle 1,2

 	oTextCursor = oTextTable.getCellByPosition(1,2).createTextCursor()
   
 	' Format zuweisen individuell
 	'oTextCursor.gotoEnd(true)
	'oTextCursor.CharColor = RGB(0, 0, 0) 
	'oTextCursor.CharFontName ="Tahoma"
 	'oTextCursor.CharHeight =10
 	
 	' oder als Vorlage
    oTextCursor.ParaStyleName = "Tabelle Abstimmung"
		
 	
	' TextCursor in Zelle 1,3

 	oTextCursor = oTextTable.getCellByPosition(1,3).createTextCursor()
    
 	' Format zuweisen individuell 
 	'oTextCursor.gotoEnd(true)
	'oTextCursor.CharColor = RGB(0, 0, 0) 
	'oTextCursor.CharFontName ="Tahoma"
 	'oTextCursor.CharHeight =10
 	
 	' oder als Vorlage
    oTextCursor.ParaStyleName = "Tabelle Abstimmung"
	 		
 
 	' Entfernen des Rahmens um die Tabelle
 	Dim oLine as new com.sun.star.table.BorderLine
	Dim row as integer, column as integer

	For row=0 To 3
		For column=0 To 1
			With oTextTable.getCellByPosition(column,row)
				.topBorder = oLine
				.rightBorder = oLine
				.leftBorder = oLine
				.bottomBorder = oLine
			End With
		Next column
	Next row
	

End Sub
Bei der Ausführung bleibt das Makro an der Stelle oTextCursor.ParaStyleName = "Tabelle Abstimmung" mit folgendem Hinweis hängen.
Wo liegt der Fehler ?


mfg
mike
Karolus
********
Beiträge: 7531
Registriert: Mo, 02.01.2006 19:48

Re: Tabelle einfügen

Beitrag von Karolus »

Hallo
Die Absatzvorlage "Tabelle Abstimmung" existiert bei dir nicht, du solltest die erst mal definieren.

Gruß Karo
LO7.4.7.2 debian 12(bookworm) auf Raspberry5 8GB (ARM64)
LO25.2.3.2 flatpak debian 12(bookworm) auf Raspberry5 8GB (ARM64)
mike6
*****
Beiträge: 479
Registriert: Sa, 06.03.2004 13:58

Re: Tabelle einfügen

Beitrag von mike6 »

Hallo Karo,

für einen kleinen "Tipp", wie ich so etwas in das Makro einbaue,
wäre ich dankbar!


mfg
mike
Karolus
********
Beiträge: 7531
Registriert: Mo, 02.01.2006 19:48

Re: Tabelle einfügen

Beitrag von Karolus »

Hallo
Ich würde die Erstellung oder Änderung einer Absatzvorlage nicht in den Code einbauen, dafür gibts ein sehr gutes GUI nämlich die Vorlagenverwaltung (→F11)
Wenn du es trotzdem versuchen willst - in Winfrieds BTL2 befinden sich ein paar Codezeilen zum ändern bereits vorhandener Absatzvorlagen.

Gruß Karo
LO7.4.7.2 debian 12(bookworm) auf Raspberry5 8GB (ARM64)
LO25.2.3.2 flatpak debian 12(bookworm) auf Raspberry5 8GB (ARM64)
Antworten