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">Option Explicit 4 5Public UserfieldDataType(14) as String 6Public oDocAuto as Object 7Public BulletList(7) as Integer 8Public sTextFieldNotDefined as String 9Public sGeneralError as String 10 11 12Sub Main() 13 Dim oCursor as Object 14 Dim oStyles as Object 15 Dim oSearchDesc as Object 16 Dim oFoundall as Object 17 Dim oFound as Object 18 Dim i as Integer 19 Dim sFoundString as String 20 Dim sFoundContent as String 21 Dim FieldStringThere as String 22 Dim ULStringThere as String 23 Dim PHStringThere as String 24 On Local Error Goto GENERALERROR 25 ' Initialization... 26 BasicLibraries.LoadLibrary("Tools") 27 If InitResources("'Template'", "tpl") Then 28 sGeneralError = GetResText(1302) 29 sTextFieldNotDefined = GetResText(1400) 30 End If 31 32 UserfieldDatatype(0) = "COMPANY" 33 UserfieldDatatype(1) = "FIRSTNAME" 34 UserfieldDatatype(2) = "NAME" 35 UserfieldDatatype(3) = "SHORTCUT" 36 UserfieldDatatype(4) = "STREET" 37 UserfieldDatatype(5) = "COUNTRY" 38 UserfieldDatatype(6) = "ZIP" 39 UserfieldDatatype(7) = "CITY" 40 UserfieldDatatype(8) = "TITLE" 41 UserfieldDatatype(9) = "POSITION" 42 UserfieldDatatype(10) = "PHONE_PRIVATE" 43 UserfieldDatatype(11) = "PHONE_COMPANY" 44 UserfieldDatatype(12) = "FAX" 45 UserfieldDatatype(13) = "EMAIL" 46 UserfieldDatatype(14) = "STATE" 47 BulletList(0) = 149 48 BulletList(1) = 34 49 BulletList(2) = 65 50 BulletList(3) = 61 51 BulletList(4) = 49 52 BulletList(5) = 47 53 BulletList(6) = 79 54 BulletList(7) = 58 55 56 oDocAuto = ThisComponent 57 oStyles = oDocAuto.Stylefamilies.GetByName("NumberingStyles") 58 59 ' Prepare the Search-Descriptor 60 oSearchDesc = oDocAuto.createsearchDescriptor() 61 oSearchDesc.SearchRegularExpression = True 62 oSearchDesc.SearchWords = True 63 oSearchDesc.SearchString = "<[^>]+>" 64 oFoundall = oDocAuto.FindAll(oSearchDesc) 65 66 'Loop over the foundings 67 For i = 0 To oFoundAll.Count - 1 68 oFound = oFoundAll.GetByIndex(i) 69 sFoundString = oFound.String 70 'Extract the string inside the brackets 71 sFoundContent = FindPartString(sFoundString,"<",">",1) 72 sFoundContent = LTrim(sFoundContent) 73 74 ' Define the Cursor and place it on the founding 75 oCursor = oFound.Text.CreateTextCursorbyRange(oFound) 76 77 ' Find out, which object is to be created... 78 FieldStringThere = Instr(1,sFoundContent,"Field") 79 ULStringThere = Instr(1,sFoundContent,"UL") 80 PHStringThere = Instr(1,sFoundContent,"Placeholder") 81 If FieldStringThere = 1 Then 82 CreateUserDatafield(oCursor, sFoundContent) 83 ElseIf ULStringThere = 1 Then 84 CreateBullet(oCursor, oStyles) 85 ElseIf PHStringThere = 1 Then 86 CreatePlaceholder(oCursor, sFoundContent) 87 End If 88 Next i 89 90 GENERALERROR: 91 If Err <> 0 Then 92 Msgbox(sGeneralError,16, GetProductName()) 93 Resume LETSGO 94 End If 95 LETSGO: 96End Sub 97 98 99' creates a User - datafield out of a string with the following structure 100' "<field:Company>" 101Sub CreateUserDatafield(oCursor, sFoundContent as String) 102 Dim MaxIndex as Integer 103 Dim sFoundList(3) 104 Dim oUserfield as Object 105 Dim UserInfo as String 106 Dim UserIndex as Integer 107 108 oUserfield = oDocAuto.CreateInstance("com.sun.star.text.TextField.ExtendedUser") 109 sFoundList() = ArrayoutofString(sFoundContent,":",MaxIndex) 110 UserInfo = UCase(LTrim(sFoundList(1))) 111 UserIndex = IndexinArray(UserInfo, UserfieldDatatype()) 112 If UserIndex <> -1 Then 113 oUserField.UserDatatype = UserIndex 114 oCursor.Text.InsertTextContent(oCursor,oUserField,True) 115 oUserField.IsFixed = True 116 Else 117 Msgbox(UserInfo &": " & sTextFieldNotDefined,16, GetProductName()) 118 End If 119End Sub 120 121 122' Creates a Bullet by setting a soft Formatation on the first unsorted List-Templates with a defined 123' Bullet Id 124Sub CreateBullet(oCursor, oStyles as Object) 125 Dim n, m, s as Integer 126 Dim StyleSet as Boolean 127 Dim ostyle as Object 128 Dim StyleName as String 129 Dim alevel() 130 StyleSet = False 131 For s = 0 To Ubound(BulletList()) 132 For n = 0 To oStyles.Count - 1 133 ostyle = oStyles.getbyindex(n) 134 StyleName = oStyle.Name 135 alevel() = ostyle.NumberingRules.getbyindex(0) 136 ' The properties of the style are stored in a Name-Value-Array() 137 For m = 0 to Ubound(alevel()) 138 ' Set the first Numbering template without a bulletID 139 If (aLevel(m).Name = "BulletId") Then 140 If alevel(m).Value = BulletList(s) Then 141 oCursor.NumberingStyle = StyleName 142 oCursor.SetString("") 143 exit Sub 144 End if 145 End If 146 Next m 147 Next n 148 Next s 149 If Not StyleSet Then 150 ' The Template with the demanded BulletID is not available, so take the first style in the sequence 151 ' that has a defined Bullet ID 152 oCursor.NumberingStyleName = oStyles.GetByIndex(5).Name 153 oCursor.SetString("") 154 End If 155End Sub 156 157 158' Creates a placeholder out of a string with the following structure: 159'<placeholder:Showtext:Helptext> 160Sub CreatePlaceholder(oCursor as Object, sFoundContent as String) 161 Dim oPlaceholder as Object 162 Dim MaxIndex as Integer 163 Dim sFoundList(3) 164 oPlaceholder = oDocAuto.CreateInstance("com.sun.star.text.TextField.JumpEdit") 165 sFoundList() = ArrayoutofString(sFoundContent, ":" & chr(34),MaxIndex) 166 ' Delete The Double-quotes 167 oPlaceholder.Hint = DeleteStr(sFoundList(2),chr(34)) 168 oPlaceholder.placeholder = DeleteStr(sFoundList(1),chr(34)) 169 oCursor.Text.InsertTextContent(oCursor,oPlaceholder,True) 170End Sub 171 172 173</script:module>