2001-04-23 04:46:42 -05:00
|
|
|
<?xml version="1.0" encoding="UTF-8"?>
|
2001-10-01 03:59:25 -05:00
|
|
|
<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
|
2001-04-23 04:46:42 -05:00
|
|
|
<script:module xmlns:script="http://openoffice.org/2000/script" script:name="AutoText" script:language="StarBasic">' BASIC
|
|
|
|
Option Explicit
|
2001-10-01 03:59:25 -05:00
|
|
|
Dim oDocument as Object
|
|
|
|
Dim sDocumentTitle as String
|
2001-04-23 04:46:42 -05:00
|
|
|
|
|
|
|
' Todo: Problem mit der Spaltenbreite lösen
|
|
|
|
' Internationale Vorlage für Überschrift
|
2001-10-01 03:59:25 -05:00
|
|
|
Sub Main()
|
|
|
|
Dim oTable as Object
|
|
|
|
Dim oRows as Object
|
|
|
|
Dim oDocuText as Object
|
|
|
|
Dim oAutoTextCursor as Object
|
|
|
|
Dim oAutoTextContainer as Object
|
|
|
|
Dim oAutogroup as Object
|
|
|
|
Dim oAutoText as Object
|
|
|
|
Dim oCharStyles as Object
|
|
|
|
Dim oContentStyle as Object
|
|
|
|
Dim oHeaderStyle as Object
|
|
|
|
Dim oGroupTitleStyle as Object
|
2001-04-23 04:46:42 -05:00
|
|
|
Dim n, m, iAutoCount as Integer
|
2001-10-01 03:59:25 -05:00
|
|
|
BasicLibraries.LoadLibrary("Tools")
|
2001-10-08 03:52:01 -05:00
|
|
|
sDocumentTitle = "Installed AutoTexts"
|
2001-04-23 04:46:42 -05:00
|
|
|
|
2001-04-25 04:10:51 -05:00
|
|
|
' Open a new empty document
|
2001-10-01 03:59:25 -05:00
|
|
|
oDocument = StarDesktop.LoadComponentFromURL("private:factory/swriter","_blank",0,NoArgs)
|
|
|
|
oDocument.DocumentInfo.Title = sDocumentTitle
|
2001-04-23 04:46:42 -05:00
|
|
|
oDocuText = oDocument.Text
|
|
|
|
|
|
|
|
' Create The Character-templates
|
|
|
|
oCharStyles = oDocument.StyleFamilies.GetByName("CharacterStyles")
|
2001-04-25 04:10:51 -05:00
|
|
|
|
2001-04-23 04:46:42 -05:00
|
|
|
' The Characterstyle for the Header that describes the Title of Autotextgroups
|
|
|
|
oGroupTitleStyle = oDocument.createInstance("com.sun.star.style.CharacterStyle")
|
|
|
|
oCharStyles.InsertbyName("AutoTextGroupTitle", oGroupTitleStyle)
|
|
|
|
|
2001-10-01 03:59:25 -05:00
|
|
|
oGroupTitleStyle.CharWeight = com.sun.star.awt.FontWeight.BOLD
|
|
|
|
oGroupTitleStyle.CharHeight = 14
|
|
|
|
|
2001-04-23 04:46:42 -05:00
|
|
|
' The Characterstyle for the Header that describes the Title of Autotextgroups
|
|
|
|
oHeaderStyle = oDocument.createInstance("com.sun.star.style.CharacterStyle")
|
|
|
|
oCharStyles.InsertbyName("AutoTextHeading", oHeaderStyle)
|
2001-10-01 03:59:25 -05:00
|
|
|
oHeaderStyle.CharWeight = com.sun.star.awt.FontWeight.BOLD
|
2001-04-25 04:10:51 -05:00
|
|
|
|
2001-04-23 04:46:42 -05:00
|
|
|
' "Ordinary" Table Content
|
|
|
|
oContentStyle = oDocument.createInstance("com.sun.star.style.CharacterStyle")
|
|
|
|
oCharStyles.InsertbyName("TableContent", oContentStyle)
|
|
|
|
|
|
|
|
oAutoTextContainer = CreateUnoService("com.sun.star.text.AutoTextContainer")
|
|
|
|
|
2001-10-01 03:59:25 -05:00
|
|
|
oAutoTextCursor = oDocuText.CreateTextCursor()
|
|
|
|
|
|
|
|
oAutoTextCursor.CharStyleName = "AutoTextGroupTitle"
|
2001-04-23 04:46:42 -05:00
|
|
|
' Link the Title with the following table
|
2001-10-01 03:59:25 -05:00
|
|
|
oAutoTextCursor.ParaKeepTogether = True
|
2001-04-23 04:46:42 -05:00
|
|
|
|
|
|
|
For n = 0 To oAutoTextContainer.Count - 1
|
|
|
|
oAutoGroup = oAutoTextContainer.GetByIndex(n)
|
|
|
|
|
2001-10-01 03:59:25 -05:00
|
|
|
oAutoTextCursor.SetString(oAutoGroup.Title)
|
|
|
|
oAutoTextCursor.CollapseToEnd()
|
|
|
|
oDocuText.insertControlCharacter(oAutoTextCursor,com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK,False)
|
2001-04-23 04:46:42 -05:00
|
|
|
oTable = oDocument.CreateInstance("com.sun.star.text.TextTable")
|
|
|
|
' Divide the table if necessary
|
|
|
|
oTable.Split = True
|
|
|
|
' oTable.KeepTogether = False
|
|
|
|
oTable.RepeatHeadLine = True
|
2001-10-01 03:59:25 -05:00
|
|
|
oAutoTextCursor.Text.InsertTextContent(oAutoTextCursor,oTable,False)
|
2001-10-08 03:52:01 -05:00
|
|
|
InsertStringToCell("AutoText Name",oTable.GetCellbyPosition(0,0), "AutoTextHeading")
|
|
|
|
InsertStringToCell("AutoText Shortcut",oTable.GetCellbyPosition(1,0), "AutoTextHeading")
|
2001-04-23 04:46:42 -05:00
|
|
|
' 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
|
2001-10-01 03:59:25 -05:00
|
|
|
oDocuText.insertControlCharacter(oAutoTextCursor,com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK,False)
|
|
|
|
oAutoTextCursor.CollapseToEnd()
|
2001-04-23 04:46:42 -05:00
|
|
|
Next n
|
|
|
|
End Sub
|
|
|
|
|
|
|
|
|
|
|
|
Sub InsertStringToCell(sCellString as String, oCell as Object, sCellStyle as String)
|
|
|
|
Dim oCellCursor as Object
|
|
|
|
oCellCursor = oCell.CreateTextCursor()
|
2001-10-01 03:59:25 -05:00
|
|
|
oCellCursor.CharStyleName = sCellStyle
|
2001-04-23 04:46:42 -05:00
|
|
|
oCell.Text.insertString(oCellCursor,sCellString,False)
|
2001-10-01 03:59:25 -05:00
|
|
|
oDocument.CurrentController.Select(oCellCursor)
|
|
|
|
End Sub</script:module>
|