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=
"Soft" script:
language=
"StarBasic">Option Explicit
7 Sub CreateStyleEnumeration()
9 EmptyListbox(DialogModel.lstSelection)
10 CurSheetName = oDocument.CurrentController.GetActiveSheet.Name
11 MakeStyleEnumeration(False)
12 DialogModel.lblSelection.Label = sTEMPLATES
16 Sub MakeStyleEnumeration(bAddToListbox as Boolean)
18 Dim aStyleFormat as Object
19 Dim Stylename as String
21 oStyles = oDocument.StyleFamilies.GetbyIndex(
0)
22 For m =
0 To oStyles.count-
1
23 oStyle = oStyles.GetbyIndex(m)
24 StyleName = oStyle.Name
25 If CheckFormatType(oStyle) Then
26 If Not bAddToListBox Then
27 AddSingleItemToListbox(DialogModel.lstSelection, Stylename)
29 SwitchNumberFormat(ostyle, oFormats, sEuroSign)
31 StyleIndex = StyleIndex +
1
32 If StyleIndex
> Ubound(StyleRangeAssignMentList()) Then
33 Redim Preserve StyleRangeAssignmentList(StyleIndex)
35 StyleRangeAssignmentList(StyleIndex) =
"<STYLENAME
>" & Stylename
& "</STYLENAME
>" & _
36 "<DEFINED
>FALSE
</DEFINED
>" & "<RANGES
></RANGES
>" &_
37 "<CELLCOUNT
>0</CELLCOUNT
>" &_
38 "<SELECTED
>FALSE
</SELECTED
>"
41 If StyleIndex
> -
1 Then
42 Redim Preserve StyleRangeAssignmentList(StyleIndex)
44 ReDim StyleRangeAssignmentList()
49 Sub AssignRangestoStyle(StyleList(), SelList())
52 Dim LastIndex as Integer
53 Dim CurStyleName as String
54 Dim AssignString as String
55 LastIndex = Ubound(StyleList())
57 SetStatusLineText(sStsRELRANGES)
58 For i =
0 To LastIndex
59 CurStyleName = StyleList(i)
60 n = PartStringInArray(StyleRangeAssignmentList(), CurStyleName,
0)
61 AssignString = StyleRangeAssignmentlist(n)
62 If IndexInArray(CurStyleName, SelList())
<> -
1 Then
63 ' Style is selected
64 If FindPartString(AssignString,
"<DEFINED
>",
"</DEFINED
>",
1) =
"FALSE
" Then
65 AssignString = ReplaceString(AssignString,
"<SELECTED
>TRUE
</SELECTED
>",
"<SELECTED
>FALSE
</SELECTED
>")
66 AssignCellFormatRanges(n, AssignString, CurStyleName)
69 ' Style is not selected
70 If FindPartString(AssignString,
"<SELECTED
>",
"</SELECTED
>",
1) =
"FALSE
" Then
71 DeselectStyle(CurStyleName, n)
74 IncreaseStatusvalue(SBRELGET/(LastIndex+
1))
79 Sub AssignCellFormatRanges(n as Integer, AssignString as String, CurStyleName as String)
80 Dim oRanges() as Object
84 Dim StyleCellCount as Long
86 Dim MaxIndex as Integer
87 Dim RangeString as String
88 Dim SheetName as String
89 Dim RangeName as String
90 Dim CellCountString as String
92 RangeString =
"<RANGES
>"
93 MaxIndex = oSheets.Count-
1
96 SheetName = oSheet.Name
97 oRanges = osheet.CellFormatRanges.CreateEnumeration
98 While oRanges.hasMoreElements
99 oRange = oRanges.NextElement
100 If oRange.getPropertyState(
"NumberFormat
") =
1 Then
101 If oRange.CellStyle = CurStyleName Then
102 oRangeAddress = oRange.RangeAddress
103 RangeName = RetrieveRangeNamefromAddress(oRange)
104 RangeString = RangeString
& RangeName
& ",
"
105 StyleCellCount = StyleCellCount + CountRangeCells(oRange)
110 If StyleCellCount
> 0 Then
111 TotCellCount = TotCellCount + StyleCellCount
112 RangeString = RTrimStr(RangeString,
",
")
113 RangeString = RangeString
& "</RANGES
>"
114 CellCountString =
"<CELLCOUNT
>" & StyleCellCount
& "</CELLCOUNT
"
115 AssignString = ReplaceString(AssignString, RangeString,
"<RANGES
></RANGES
>")
116 AssignString = ReplaceString(AssignString, CellCountString,
"<CELLCOUNT
>0</CELLCOUNT
>")
118 AssignString = ReplaceString(AssignString,
"<DEFINED
>TRUE
</DEFINED
>",
"<DEFINED
>FALSE
</DEFINED
>")
119 StyleRangeAssignmentList(n) = AssignString
123 ' deletes a styletemplate from the Collection that selects the ranges
124 Sub DeselectStyle(DeSelStyleName as String, n as Integer)
126 Dim RangeName as String
127 Dim SelectString as String
128 Dim AssignString as String
129 Dim StyleRangeList() as String
130 Dim MaxIndex as Integer
131 SelectString =
"<SELECTED
>FALSE
</SELECTED
>"
132 AssignString = StyleRangeAssignmentList(n)
133 RangeString = FindPartString(AssignString,
"<RANGES
>",
"</RANGES
>",
1)
134 StyleRangeList() = ArrayoutofString(RangeString,
",
")
135 MaxIndex = Ubound(StyleRangeList())
136 For i =
0 To MaxIndex
137 RangeName = StyleRangeList(i)
138 If oSelRanges.HasbyName(RangeName) Then
139 oSelRanges.RemovebyName(RangeName)
142 AssignString = ReplaceString(AssignString,
"<SELECTED
>FALSE
</SELECTED
>",
"<SELECTED
>TRUE
</SELECTED
>")
143 StyleRangeAssignmentList(n) = AssignString
147 Function RetrieveRangeNamefromAddress(oRange as Object) as String
148 Dim Rangename as String
149 Dim oAddressRanges as Object
150 oAddressRanges = oDocument.createInstance(
"com.sun.star.sheet.SheetCellRanges
")
151 oAddressRanges.InsertbyName(
"",oRange)
152 Rangename = oAddressRanges.RangeAddressesasString
153 ' Msgbox
"Adresse:
" & oRangeAddress.StartColumn
& " ;
" & oRangeAddress.EndColumn
& " ;
" & oRangeAddress.StartRow
& " ;
" & oRangeAddress.EndRow
& chr(
13)
& RangeName
154 ' oAddressRanges.RemovebyName(RangeName)
155 RetrieveRangeNamefromAddress = Rangename
159 ' creates a sheet object from an according sectionname
160 Function RetrieveSheetoutofRangeName(TableText as String)
161 Dim DescriptionList() as String
162 Dim SheetName as String
163 Dim MaxIndex as integer
164 ' find out in which sheet the range is
165 DescriptionList() = ArrayOutofString(TableText,
".
",MaxIndex)
166 SheetName = DescriptionList(
0)
167 SheetName = DeleteStr(SheetName,
"'")
168 ' set the viewcursor on this sheet
169 RetrieveSheetoutofRangeName = oSheets.GetbyName(SheetName)
173 ' creates a rangeobject from an according rangename
174 Function RetrieveRangeoutofRangeName(TableText as String)
175 oSheet = RetrieveSheetoutofRangeName(TableText)
176 oRange = oSheet.GetCellRangebyName(TableText)
177 RetrieveRangeoutofRangeName = oRange
181 Sub ConvertTheSoftWay(StyleList(), bDeSelect as Boolean)
186 Dim CurStyleName as String
187 Dim RangeName as String
188 Dim OldStatusValue as Integer
189 Dim LastIndex as Integer
190 Dim oSelListbox as Object
191 Dim StyleRangeList() as String
192 Dim MaxIndex as Integer
193 oSelListbox = DialogConvert.GetControl(
"lstSelection
")
194 LastIndex = Ubound(StyleList())
195 OldStatusValue = StatusValue
196 For i =
0 To LastIndex
197 CurStyleName = StyleList(i)
198 oStyle = oStyles.GetbyName(CurStyleName)
199 StyleRangeList() = GetAssignedRanges(CurStyleName, n)
200 MaxIndex = Ubound(StyleRangeList())
201 For s =
0 To MaxIndex
202 RangeName = StyleRangeList(s)
203 oRange = RetrieveRangeoutofRangeName(RangeName)
204 If oRange.getPropertyState(
"NumberFormat
") =
1 Then
205 ' Range is hard formatted
206 ConvertCellCurrencies(oRange)
207 CurCellCount = CountRangeCells(oRange)
209 IncreaseStatusvalue((CurCellCount/TotCellCount)*(
95-OldStatusValue))
211 ' Note: On Problems see Bug #
73157
212 If oSelRanges.HasbyName(RangeName) Then
213 oSelRanges.RemovebyName(RangeName)
214 oDocument.CurrentController.Select(oSelRanges)
218 SwitchNumberFormat(ostyle, oFormats, sEuroSign)
219 StyleRangeAssignmentList(n) =
""
220 l = GetItemPos(oSelListBox.Model, CurStyleName)
221 oSelListbox.RemoveItems(l,
1)
226 Function GetAssignedRanges(CurStyleName as String, n as Integer)
227 Dim StyleRangeList() as String
228 Dim RangeString as String
229 Dim AssignString as String
230 n = PartStringInArray(StyleRangeAssignmentList(), CurStyleName,
0)
231 If n
<> -
1 Then
232 AssignString = StyleRangeAssignmentList(n)
233 RangeString = FindPartString(AssignString,
"<RANGES
>",
"</RANGES
>",
1)
234 If RangeString
<> "" Then
235 StyleRangeList() = ArrayoutofString(RangeString,
",
")
238 GetAssignedRanges() = StyleRangeList()
239 End Function
</script:module>