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
Wo liegt der Fehler ?
mfg
mike