home *** CD-ROM | disk | FTP | other *** search
- <?xml version="1.0" encoding="UTF-8"?>
-
- <script:module xmlns:script="http://openoffice.org/2000/script" script:name="AutoText" script:language="StarBasic">' BASIC
- Option Explicit
-
- ' Todo: Problem mit der Spaltenbreite l├╢sen
- ' Internationale Vorlage für Überschrift
- Sub Main
- Dim oDocument, oTable, oRows, oDocuText, oTitleCursor as Object
- Dim oAutoTextContainer, oAutogroup, oAutoText as Object
- Dim oCharStyles, oContentStyle, oHeaderStyle, oGroupTitleStyle as Object
- Dim n, m, iAutoCount as Integer
-
- BasicLibraries.LoadLibrary("Tools")
- LoadLanguage(StarDesktop.ISOLocale.Language)
-
- ' Open a new empty document
- oDocument = StarDesktop.LoadComponentFromURL("staroffice:factory/swriter","_blank",0,NoArgs)
- oDocuText = oDocument.Text
-
- ' Create The Character-templates
- oCharStyles = oDocument.StyleFamilies.GetByName("CharacterStyles")
-
- ' The Characterstyle for the Header that describes the Title of Autotextgroups
- oGroupTitleStyle = oDocument.createInstance("com.sun.star.style.CharacterStyle")
- oGroupTitleStyle.charWeight = com.sun.star.awt.FontWeight.BOLD
- oGroupTitleStyle.CharHeight = 14
- oCharStyles.InsertbyName("AutoTextGroupTitle", oGroupTitleStyle)
-
- ' The Characterstyle for the Header that describes the Title of Autotextgroups
- oHeaderStyle = oDocument.createInstance("com.sun.star.style.CharacterStyle")
- oHeaderStyle.charWeight = com.sun.star.awt.FontWeight.BOLD
- oCharStyles.InsertbyName("AutoTextHeading", oHeaderStyle)
-
- ' "Ordinary" Table Content
- oContentStyle = oDocument.createInstance("com.sun.star.style.CharacterStyle")
- oCharStyles.InsertbyName("TableContent", oContentStyle)
-
- oAutoTextContainer = CreateUnoService("com.sun.star.text.AutoTextContainer")
-
- oTitleCursor = oDocuText.CreateTextCursor()
- oTitleCursor.CharStyle = "AutoTextGroupTitle"
- ' Link the Title with the following table
- oTitleCursor.ParaKeepTogether = True
-
- For n = 0 To oAutoTextContainer.Count - 1
- oAutoGroup = oAutoTextContainer.GetByIndex(n)
-
- oTitleCursor.SetString(oAutoGroup.Title)
- oTitleCursor.CollapseToEnd()
- oDocuText.insertControlCharacter(oCursor,com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK,False)
- oTable = oDocument.CreateInstance("com.sun.star.text.TextTable")
- ' Divide the table if necessary
- oTable.Split = True
- ' oTable.KeepTogether = False
- oTable.RepeatHeadLine = True
- oTitleCursor.Text.InsertTextContent(oCursor,oTable,False)
- InsertStringToCell("AutoText-Title",oTable.GetCellbyPosition(0,0), "AutoTextHeading")
- InsertStringToCell("AutoText-Name",oTable.GetCellbyPosition(1,0), "AutoTextHeading")
- ' Insert one row at the bottom of the table
- oRows = oTable.Rows
- iAutoCount = oAutoGroup.Count
- For m = 0 To iAutoCount-1
- ' Insert the name and the title of all Autotexts
- oAutoText = oAutoGroup.GetByIndex(m)
- InsertStringToCell(oAutoGroup.Titles(m), oTable.GetCellbyPosition(0, m + 1), "TableContent")
- InsertStringToCell(oAutoGroup.ElementNames(m), oTable.GetCellbyPosition(1, m + 1), "TableContent")
- If m < iAutoCount-1 Then
- oRows.InsertbyIndex(m + 2,1)
- End If
- Next m
- oDocuText.insertControlCharacter(oCursor,com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK,False)
- oCursor.CollapseToEnd()
- Next n
- End Sub
-
-
- Sub InsertStringToCell(sCellString as String, oCell as Object, sCellStyle as String)
- Dim oCellCursor as Object
- oCellCursor = oCell.CreateTextCursor()
- oCellCursor.CharStyle = sCellStyle
- oCell.Text.insertString(oCellCursor,sCellString,False)
- End Sub</script:module>
-