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=
"Hard" script:
language=
"StarBasic">REM ***** BASIC *****
8 Dim MaxIndex as Integer
10 EnableStep1DialogControls(False, False, False)
12 DialogModel.lblSelection.Label = sCURRRANGES
13 EmptyListbox(DialogModel.lstSelection)
14 oDocument.CurrentController.Select(oSelRanges)
15 If (DialogModel.optSheetRanges.State =
1) AND (DialogModel.chkComplete.State
<> 1) Then
16 ' Conversion on a sheet?
17 SetStatusLineText(sStsRELRANGES)
18 osheet = oDocument.CurrentController.GetActiveSheet
19 oRanges = osheet.CellFormatRanges.createEnumeration()
20 MaxIndex = AddSheetRanges(oRanges, MaxIndex, oSheet, False)
21 If MaxIndex
> -
1 Then
22 ReDim Preserve RangeList(MaxIndex)
25 CreateRangeEnumeration(False)
26 bRangeListDefined = True
28 EnableStep1DialogControls(True, True, True)
29 SetStatusLineText(
"")
33 Sub CreateRangeEnumeration(bAutopilot as Boolean)
35 Dim MaxIndex as integer
36 Dim sStatustext as String
38 If Not bRangeListDefined Then
39 ' Cellranges are not yet defined
40 oSheets = oDocument.Sheets
41 For i =
0 To oSheets.Count-
1
42 oSheet = oSheets.GetbyIndex(i)
44 IncreaseStatusValue(SBRELGET/osheets.Count)
46 sStatustext = ReplaceString(sStsRELSHEETRANGES,Str(i+
1),
"%
1Number%
1")
47 sStatustext = ReplaceString(sStatusText,oSheets.Count,
"%
2TotPageCount%
2")
48 SetStatusLineText(sStatusText)
50 oRanges = osheet.CellFormatRanges.createEnumeration
51 MaxIndex = AddSheetRanges(oRanges, MaxIndex, oSheet, bAutopilot)
54 If Not bAutoPilot Then
55 SetStatusLineText(sStsRELRANGES)
56 ' cellranges already defined
57 For i =
0 To Ubound(RangeList())
58 If RangeList(i)
<> "" Then
59 AddSingleItemToListBox(DialogModel.lstSelection, RangeList(i))
64 If MaxIndex
> -
1 Then
65 ReDim Preserve RangeList(MaxIndex)
73 Function AddSheetRanges(oRanges as Object, r as Integer, oSheet as Object, bAutopilot)
74 Dim RangeName as String
75 Dim AddtoList as Boolean
76 Dim iCurStep as Integer
77 Dim MaxIndex as Integer
78 iCurStep = DialogModel.Step
79 While oRanges.hasMoreElements
80 oRange = oRanges.NextElement
81 AddToList = CheckFormatType(oRange)
83 RangeName = RetrieveRangeNamefromAddress(oRange)
84 TotCellCount = TotCellCount + CountRangeCells(oRange)
85 If Not bAutoPilot Then
86 AddSingleItemToListbox(DialogModel.lstSelection, RangeName)
88 ' The Ranges are only passed to an Array when the whole Document is the basis
89 ' Redimension the RangeList Array if necessary
90 MaxIndex = Ubound(RangeList())
92 If r
> MaxIndex Then
93 MaxIndex = MaxIndex + SBRANGEUBOUND
94 ReDim Preserve RangeList(MaxIndex)
96 RangeList(r) = RangeName
103 ' adds a section to the collection
106 Dim RangeName as String
107 Dim SelItem as String
108 Dim CurRange as String
109 Dim SheetRangeName as String
110 Dim DescriptionList() as String
111 Dim MaxRangeIndex as Integer
112 Dim StatusValue as Integer
114 MaxRangeIndex = Ubound(SelRangeList())
115 CurSheetName = oSheet.Name
116 For i =
0 To MaxRangeIndex
117 SelItem = SelRangeList(i)
118 ' Is the Range already included in the collection?
119 oRange = RetrieveRangeoutOfRangename(SelItem)
120 TotCellCount = TotCellCount + CountRangeCells(oRange)
121 DescriptionList() = ArrayOutofString(SelItem,
".
",
1)
122 SheetRangeName = DeleteStr(DescriptionList(
0),
"'")
123 If SheetRangeName = CurSheetName Then
124 oSelRanges.InsertbyName(
"",oRange)
126 IncreaseStatusValue(SBRELGET/MaxRangeIndex)
131 Sub ConvertThehardWay(ListboxList(), SwitchFormat as Boolean, bRemove as Boolean)
134 Dim OldStatusValue as Single
135 Dim RangeName as String
136 Dim LastIndex as Integer
137 Dim oSelListbox as Object
139 oSelListbox = DialogConvert.GetControl(
"lstSelection
")
140 Lastindex = Ubound(ListboxList())
141 If TotCellCount
> 0 Then
142 OldStatusValue = StatusValue
144 For i =
0 To LastIndex
145 RangeName = ListboxList(i)
146 oRange = RetrieveRangeoutofRangeName(RangeName)
147 ConvertCellCurrencies(oRange)
149 If oSelRanges.HasbyName(RangeName) Then
150 oSelRanges.RemovebyName(RangeName)
151 oDocument.CurrentController.Select(oSelRanges)
155 If oRange.getPropertyState(
"NumberFormat
")
<> 1 Then
156 ' Range is hard formatted
157 SwitchNumberFormat(oRange, oFormats, sEuroSign)
160 SwitchNumberFormat(oRange, oFormats, sEuroSign)
162 AddCells = CountRangeCells(oRange)
163 CurCellCount = AddCells
164 IncreaseStatusValue((CurCellCount/TotCellCount)*(
100-OldStatusValue))
166 RemoveListBoxItemByName(oSelListbox.Model,Rangename)
173 Sub ConvertCellCurrencies(oRange as Object)
174 Dim oValues as Object
177 oValues = oRange.queryContentCells(com.sun.star.sheet.CellFlags.VALUE)
178 If (oValues.Count
> 0) Then
179 oCells = oValues.Cells.createEnumeration
180 While oCells.hasMoreElements
181 oCell = oCells.nextElement
182 ModifyObjectValuewithCurrFactor(oCell)
188 Sub ModifyObjectValuewithCurrFactor(oDocObject as Object)
189 Dim oDocObjectValue as double
190 oDocObjectValue = oDocObject.Value
191 oDocObject.Value = Round(oDocObjectValue/CurrFactor,
2)
195 Function CheckIfRangeisCurrency(FormatObject as Object)
196 Dim oFormatofObject() as Object
197 ' Retrieve the Format of the Object
198 On Local Error GoTo NOKEY
199 oFormatofObject() = oFormats.getByKey(FormatObject.NumberFormat)
200 On Local Error GoTo
0
201 CheckIfRangeIsCurrency = INT(oFormatofObject.Type) AND com.sun.star.util.NumberFormat.CURRENCY
204 CheckIfRangeisCurrency = False
210 Function CountColumnsForRow(IndexArray() as String, Row as Integer)
212 Dim NoNulls as Boolean
213 For i =
1 To Ubound(IndexArray,
2)
214 If IndexArray(Row,i)=
"" Then
219 CountColumnsForRow = i
223 Function CountRangeCells(oRange as Object) As Long
224 Dim oRangeAddress as Object
225 Dim LocCellCount as Long
226 oRangeAddress = oRange.RangeAddress
227 LocCellCount = (oRangeAddress.EndColumn - oRangeAddress.StartColumn +
1) * (oRangeAddress.EndRow - oRangeAddress.StartRow +
1)
228 CountRangeCells = LocCellCount
229 End Function
</script:module>