1<?xml version="1.0" encoding="UTF-8"?>
2<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
3<script:module xmlns:script="http://openoffice.org/2000/script" script:name="AutoText" script:language="StarBasic">&apos; BASIC
4Option Explicit
5Dim oDocument as Object
6Dim sDocumentTitle as String
7
8
9Sub Main()
10Dim oTable as Object
11Dim oRows as Object
12Dim oDocuText as Object
13Dim oAutoTextCursor as Object
14Dim oAutoTextContainer as Object
15Dim oAutogroup as Object
16Dim oAutoText as Object
17Dim oCharStyles as Object
18Dim oContentStyle as Object
19Dim oHeaderStyle as Object
20Dim oGroupTitleStyle as Object
21Dim n, m, iAutoCount as Integer
22	BasicLibraries.LoadLibrary(&quot;Tools&quot;)
23	sDocumentTitle = &quot;Installed AutoTexts&quot;
24
25	&apos; Open a new empty document
26	oDocument = CreateNewDocument(&quot;swriter&quot;)
27	If Not IsNull(oDocument) Then
28		oDocument.DocumentProperties.Title = sDocumentTitle
29		oDocuText = oDocument.Text
30
31		&apos; Create The Character-templates
32		oCharStyles = oDocument.StyleFamilies.GetByName(&quot;CharacterStyles&quot;)
33
34		&apos; The Characterstyle for the Header that describes the Title of Autotextgroups
35		oGroupTitleStyle = oDocument.createInstance(&quot;com.sun.star.style.CharacterStyle&quot;)
36		oCharStyles.InsertbyName(&quot;AutoTextGroupTitle&quot;, oGroupTitleStyle)
37
38		oGroupTitleStyle.CharWeight = com.sun.star.awt.FontWeight.BOLD
39		oGroupTitleStyle.CharHeight = 14
40
41		&apos; The Characterstyle for the Header that describes the Title of Autotextgroups
42		oHeaderStyle = oDocument.createInstance(&quot;com.sun.star.style.CharacterStyle&quot;)
43		oCharStyles.InsertbyName(&quot;AutoTextHeading&quot;, oHeaderStyle)
44		oHeaderStyle.CharWeight = com.sun.star.awt.FontWeight.BOLD
45
46		&apos; &quot;Ordinary&quot; Table Content
47		oContentStyle = oDocument.createInstance(&quot;com.sun.star.style.CharacterStyle&quot;)
48		oCharStyles.InsertbyName(&quot;TableContent&quot;, oContentStyle)
49
50		oAutoTextContainer = CreateUnoService(&quot;com.sun.star.text.AutoTextContainer&quot;)
51
52		oAutoTextCursor = oDocuText.CreateTextCursor()
53
54		oAutoTextCursor.CharStyleName = &quot;AutoTextGroupTitle&quot;
55		&apos; Link the Title with the following table
56		oAutoTextCursor.ParaKeepTogether = True
57
58		For n = 0 To oAutoTextContainer.Count - 1
59			oAutoGroup = oAutoTextContainer.GetByIndex(n)
60
61			oAutoTextCursor.SetString(oAutoGroup.Title)
62			oAutoTextCursor.CollapseToEnd()
63   			oDocuText.insertControlCharacter(oAutoTextCursor,com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK,False)
64			oTable = oDocument.CreateInstance(&quot;com.sun.star.text.TextTable&quot;)
65			&apos; Divide the table if necessary
66			oTable.Split = True
67&apos;			oTable.KeepTogether = False
68			oTable.RepeatHeadLine = True
69			oAutoTextCursor.Text.InsertTextContent(oAutoTextCursor,oTable,False)
70			InsertStringToCell(&quot;AutoText Name&quot;,oTable.GetCellbyPosition(0,0), &quot;AutoTextHeading&quot;)
71			InsertStringToCell(&quot;AutoText Shortcut&quot;,oTable.GetCellbyPosition(1,0), &quot;AutoTextHeading&quot;)
72			&apos; Insert one row at the bottom of the table
73			oRows = oTable.Rows
74			iAutoCount = oAutoGroup.Count
75			For m = 0 To iAutoCount-1
76				&apos; Insert the name and the title of all Autotexts
77				oAutoText = oAutoGroup.GetByIndex(m)
78				InsertStringToCell(oAutoGroup.Titles(m), oTable.GetCellbyPosition(0, m + 1), &quot;TableContent&quot;)
79				InsertStringToCell(oAutoGroup.ElementNames(m), oTable.GetCellbyPosition(1, m + 1), &quot;TableContent&quot;)
80				If m &lt; iAutoCount-1 Then
81					oRows.InsertbyIndex(m + 2,1)
82				End If
83			Next m
84	   		oDocuText.insertControlCharacter(oAutoTextCursor,com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK,False)
85			oAutoTextCursor.CollapseToEnd()
86		Next n
87	End If
88End Sub
89
90
91Sub InsertStringToCell(sCellString as String, oCell as Object, sCellStyle as String)
92Dim oCellCursor as Object
93	oCellCursor = oCell.CreateTextCursor()
94	oCellCursor.CharStyleName = sCellStyle
95	oCell.Text.insertString(oCellCursor,sCellString,False)
96	oDocument.CurrentController.Select(oCellCursor)
97End Sub</script:module>
98