1 <?xml version=
"1.0" encoding=
"UTF-8"?>
2 <!DOCTYPE script:module PUBLIC
"-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
4 * This file is part of the LibreOffice project.
6 * This Source Code Form is subject to the terms of the Mozilla Public
7 * License, v. 2.0. If a copy of the MPL was not distributed with this
8 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 * This file incorporates work covered by the following license notice:
12 * Licensed to the Apache Software Foundation (ASF) under one or more
13 * contributor license agreements. See the NOTICE file distributed
14 * with this work for additional information regarding copyright
15 * ownership. The ASF licenses this file to you under the Apache
16 * License, Version 2.0 (the "License"); you may not use this file
17 * except in compliance with the License. You may obtain a copy of
18 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 <script:module xmlns:
script=
"http://openoffice.org/2000/script" script:
name=
"Soft" script:
language=
"StarBasic">Option Explicit
24 Sub CreateStyleEnumeration()
26 EmptyListbox(DialogModel.lstSelection)
27 CurSheetName = oDocument.CurrentController.GetActiveSheet.Name
28 MakeStyleEnumeration(False)
29 DialogModel.lblSelection.Label = sTEMPLATES
33 Sub MakeStyleEnumeration(bAddToListbox as Boolean)
35 Dim aStyleFormat as Object
36 Dim Stylename as String
38 oStyles = oDocument.StyleFamilies.GetbyIndex(
0)
39 For m =
0 To oStyles.count-
1
40 oStyle = oStyles.GetbyIndex(m)
41 StyleName = oStyle.Name
42 If CheckFormatType(oStyle) Then
43 If Not bAddToListBox Then
44 AddSingleItemToListbox(DialogModel.lstSelection, Stylename)
46 SwitchNumberFormat(ostyle, oFormats, sEuroSign)
48 StyleIndex = StyleIndex +
1
49 If StyleIndex
> Ubound(StyleRangeAssignMentList()) Then
50 Redim Preserve StyleRangeAssignmentList(StyleIndex)
52 StyleRangeAssignmentList(StyleIndex) =
"<STYLENAME
>" & Stylename
& "</STYLENAME
>" & _
53 "<DEFINED
>FALSE
</DEFINED
>" & "<RANGES
></RANGES
>" &_
54 "<CELLCOUNT
>0</CELLCOUNT
>" &_
55 "<SELECTED
>FALSE
</SELECTED
>"
58 If StyleIndex
> -
1 Then
59 Redim Preserve StyleRangeAssignmentList(StyleIndex)
61 ReDim StyleRangeAssignmentList()
66 Sub AssignRangestoStyle(StyleList(), SelList())
69 Dim LastIndex as Integer
70 Dim CurStyleName as String
71 Dim AssignString as String
72 LastIndex = Ubound(StyleList())
74 SetStatusLineText(sStsRELRANGES)
75 For i =
0 To LastIndex
76 CurStyleName = StyleList(i)
77 n = PartStringInArray(StyleRangeAssignmentList(), CurStyleName,
0)
78 AssignString = StyleRangeAssignmentlist(n)
79 If IndexInArray(CurStyleName, SelList())
<> -
1 Then
80 ' Style is selected
81 If FindPartString(AssignString,
"<DEFINED
>",
"</DEFINED
>",
1) =
"FALSE
" Then
82 AssignString = ReplaceString(AssignString,
"<SELECTED
>TRUE
</SELECTED
>",
"<SELECTED
>FALSE
</SELECTED
>")
83 AssignCellFormatRanges(n, AssignString, CurStyleName)
86 ' Style is not selected
87 If FindPartString(AssignString,
"<SELECTED
>",
"</SELECTED
>",
1) =
"FALSE
" Then
88 DeselectStyle(CurStyleName, n)
91 IncreaseStatusvalue(SBRELGET/(LastIndex+
1))
96 Sub AssignCellFormatRanges(n as Integer, AssignString as String, CurStyleName as String)
97 Dim oRanges() as Object
101 Dim StyleCellCount as Long
103 Dim MaxIndex as Integer
104 Dim RangeString as String
105 Dim SheetName as String
106 Dim RangeName as String
107 Dim CellCountString as String
109 RangeString =
"<RANGES
>"
110 MaxIndex = oSheets.Count-
1
111 For i =
0 To MaxIndex
113 SheetName = oSheet.Name
114 oRanges = osheet.CellFormatRanges.CreateEnumeration
115 While oRanges.hasMoreElements
116 oRange = oRanges.NextElement
117 If oRange.getPropertyState(
"NumberFormat
") =
1 Then
118 If oRange.CellStyle = CurStyleName Then
119 oRangeAddress = oRange.RangeAddress
120 RangeName = RetrieveRangeNamefromAddress(oRange)
121 RangeString = RangeString
& RangeName
& ",
"
122 StyleCellCount = StyleCellCount + CountRangeCells(oRange)
127 If StyleCellCount
> 0 Then
128 TotCellCount = TotCellCount + StyleCellCount
129 RangeString = RTrimStr(RangeString,
",
")
130 RangeString = RangeString
& "</RANGES
>"
131 CellCountString =
"<CELLCOUNT
>" & StyleCellCount
& "</CELLCOUNT
"
132 AssignString = ReplaceString(AssignString, RangeString,
"<RANGES
></RANGES
>")
133 AssignString = ReplaceString(AssignString, CellCountString,
"<CELLCOUNT
>0</CELLCOUNT
>")
135 AssignString = ReplaceString(AssignString,
"<DEFINED
>TRUE
</DEFINED
>",
"<DEFINED
>FALSE
</DEFINED
>")
136 StyleRangeAssignmentList(n) = AssignString
140 ' deletes a styletemplate from the Collection that selects the ranges
141 Sub DeselectStyle(DeSelStyleName as String, n as Integer)
143 Dim RangeName as String
144 Dim SelectString as String
145 Dim AssignString as String
146 Dim StyleRangeList() as String
147 Dim MaxIndex as Integer
148 SelectString =
"<SELECTED
>FALSE
</SELECTED
>"
149 AssignString = StyleRangeAssignmentList(n)
150 RangeString = FindPartString(AssignString,
"<RANGES
>",
"</RANGES
>",
1)
151 StyleRangeList() = ArrayoutofString(RangeString,
",
")
152 MaxIndex = Ubound(StyleRangeList())
153 For i =
0 To MaxIndex
154 RangeName = StyleRangeList(i)
155 If oSelRanges.HasbyName(RangeName) Then
156 oSelRanges.RemovebyName(RangeName)
159 AssignString = ReplaceString(AssignString,
"<SELECTED
>FALSE
</SELECTED
>",
"<SELECTED
>TRUE
</SELECTED
>")
160 StyleRangeAssignmentList(n) = AssignString
164 Function RetrieveRangeNamefromAddress(oRange as Object) as String
165 Dim Rangename as String
166 Dim oAddressRanges as Object
167 oAddressRanges = oDocument.createInstance(
"com.sun.star.sheet.SheetCellRanges
")
168 oAddressRanges.InsertbyName(
"",oRange)
169 Rangename = oAddressRanges.RangeAddressesasString
170 ' Msgbox
"Adresse:
" & oRangeAddress.StartColumn
& " ;
" & oRangeAddress.EndColumn
& " ;
" & oRangeAddress.StartRow
& " ;
" & oRangeAddress.EndRow
& chr(
13)
& RangeName
171 ' oAddressRanges.RemovebyName(RangeName)
172 RetrieveRangeNamefromAddress = Rangename
176 ' creates a sheet object from an according sectionname
177 Function RetrieveSheetoutofRangeName(TableText as String)
178 Dim DescriptionList() as String
179 Dim SheetName as String
180 Dim MaxIndex as integer
181 ' find out in which sheet the range is
182 DescriptionList() = ArrayOutofString(TableText,
".
",MaxIndex)
183 SheetName = DescriptionList(
0)
184 SheetName = DeleteStr(SheetName,
"'")
185 ' set the viewcursor on this sheet
186 RetrieveSheetoutofRangeName = oSheets.GetbyName(SheetName)
190 ' creates a rangeobject from an according rangename
191 Function RetrieveRangeoutofRangeName(TableText as String)
192 oSheet = RetrieveSheetoutofRangeName(TableText)
193 oRange = oSheet.GetCellRangebyName(TableText)
194 RetrieveRangeoutofRangeName = oRange
198 Sub ConvertTheSoftWay(StyleList(), bDeSelect as Boolean)
203 Dim CurStyleName as String
204 Dim RangeName as String
205 Dim OldStatusValue as Integer
206 Dim LastIndex as Integer
207 Dim oSelListbox as Object
208 Dim StyleRangeList() as String
209 Dim MaxIndex as Integer
210 oSelListbox = DialogConvert.GetControl(
"lstSelection
")
211 LastIndex = Ubound(StyleList())
212 OldStatusValue = StatusValue
213 For i =
0 To LastIndex
214 CurStyleName = StyleList(i)
215 oStyle = oStyles.GetbyName(CurStyleName)
216 StyleRangeList() = GetAssignedRanges(CurStyleName, n)
217 MaxIndex = Ubound(StyleRangeList())
218 For s =
0 To MaxIndex
219 RangeName = StyleRangeList(s)
220 oRange = RetrieveRangeoutofRangeName(RangeName)
221 If oRange.getPropertyState(
"NumberFormat
") =
1 Then
222 ' Range is hard formatted
223 ConvertCellCurrencies(oRange)
224 CurCellCount = CountRangeCells(oRange)
226 IncreaseStatusvalue((CurCellCount/TotCellCount)*(
95-OldStatusValue))
228 ' Note: On Problems see Bug #
73157
229 If oSelRanges.HasbyName(RangeName) Then
230 oSelRanges.RemovebyName(RangeName)
231 oDocument.CurrentController.Select(oSelRanges)
235 SwitchNumberFormat(ostyle, oFormats, sEuroSign)
236 StyleRangeAssignmentList(n) =
""
237 l = GetItemPos(oSelListBox.Model, CurStyleName)
238 oSelListbox.RemoveItems(l,
1)
243 Function GetAssignedRanges(CurStyleName as String, n as Integer)
244 Dim StyleRangeList() as String
245 Dim RangeString as String
246 Dim AssignString as String
247 n = PartStringInArray(StyleRangeAssignmentList(), CurStyleName,
0)
248 If n
<> -
1 Then
249 AssignString = StyleRangeAssignmentList(n)
250 RangeString = FindPartString(AssignString,
"<RANGES
>",
"</RANGES
>",
1)
251 If RangeString
<> "" Then
252 StyleRangeList() = ArrayoutofString(RangeString,
",
")
255 GetAssignedRanges() = StyleRangeList()
256 End Function
</script:module>