1cdf0e10cSrcweir<?xml version="1.0" encoding="UTF-8"?> 2cdf0e10cSrcweir<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd"> 33e02b54dSAndrew Rist<!--*********************************************************** 4*b53bcc32SMatthias Seidel * 53e02b54dSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 63e02b54dSAndrew Rist * or more contributor license agreements. See the NOTICE file 73e02b54dSAndrew Rist * distributed with this work for additional information 83e02b54dSAndrew Rist * regarding copyright ownership. The ASF licenses this file 93e02b54dSAndrew Rist * to you under the Apache License, Version 2.0 (the 103e02b54dSAndrew Rist * "License"); you may not use this file except in compliance 113e02b54dSAndrew Rist * with the License. You may obtain a copy of the License at 12*b53bcc32SMatthias Seidel * 133e02b54dSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 14*b53bcc32SMatthias Seidel * 153e02b54dSAndrew Rist * Unless required by applicable law or agreed to in writing, 163e02b54dSAndrew Rist * software distributed under the License is distributed on an 173e02b54dSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 183e02b54dSAndrew Rist * KIND, either express or implied. See the License for the 193e02b54dSAndrew Rist * specific language governing permissions and limitations 203e02b54dSAndrew Rist * under the License. 21*b53bcc32SMatthias Seidel * 223e02b54dSAndrew Rist ***********************************************************--> 23*b53bcc32SMatthias Seidel<script:module xmlns:script="http://openoffice.org/2000/script" script:name="Hard" script:language="StarBasic">REM ***** BASIC ***** 24cdf0e10cSrcweirOption Explicit 25cdf0e10cSrcweir 26cdf0e10cSrcweir 27cdf0e10cSrcweirSub CreateRangeList() 28cdf0e10cSrcweirDim MaxIndex as Integer 29cdf0e10cSrcweir MaxIndex = -1 30cdf0e10cSrcweir EnableStep1DialogControls(False, False, False) 31cdf0e10cSrcweir EmptySelection() 32cdf0e10cSrcweir DialogModel.lblSelection.Label = sCURRRANGES 33cdf0e10cSrcweir EmptyListbox(DialogModel.lstSelection) 34cdf0e10cSrcweir oDocument.CurrentController.Select(oSelRanges) 35cdf0e10cSrcweir If (DialogModel.optSheetRanges.State = 1) AND (DialogModel.chkComplete.State <> 1) Then 36cdf0e10cSrcweir ' Conversion on a sheet? 37cdf0e10cSrcweir SetStatusLineText(sStsRELRANGES) 38cdf0e10cSrcweir osheet = oDocument.CurrentController.GetActiveSheet 39cdf0e10cSrcweir oRanges = osheet.CellFormatRanges.createEnumeration() 40cdf0e10cSrcweir MaxIndex = AddSheetRanges(oRanges, MaxIndex, oSheet, False) 41cdf0e10cSrcweir If MaxIndex > -1 Then 42cdf0e10cSrcweir ReDim Preserve RangeList(MaxIndex) 43cdf0e10cSrcweir End If 44cdf0e10cSrcweir Else 45cdf0e10cSrcweir CreateRangeEnumeration(False) 46cdf0e10cSrcweir bRangeListDefined = True 47cdf0e10cSrcweir End If 48cdf0e10cSrcweir EnableStep1DialogControls(True, True, True) 49cdf0e10cSrcweir SetStatusLineText("") 50cdf0e10cSrcweirEnd Sub 51cdf0e10cSrcweir 52cdf0e10cSrcweir 53cdf0e10cSrcweirSub CreateRangeEnumeration(bAutopilot as Boolean) 54cdf0e10cSrcweirDim i as Integer 55cdf0e10cSrcweirDim MaxIndex as integer 56cdf0e10cSrcweirDim sStatustext as String 57cdf0e10cSrcweir MaxIndex = -1 58cdf0e10cSrcweir If Not bRangeListDefined Then 59cdf0e10cSrcweir ' Cellranges are not yet defined 60cdf0e10cSrcweir oSheets = oDocument.Sheets 61cdf0e10cSrcweir For i = 0 To oSheets.Count-1 62cdf0e10cSrcweir oSheet = oSheets.GetbyIndex(i) 63cdf0e10cSrcweir If bAutopilot Then 64cdf0e10cSrcweir IncreaseStatusValue(SBRELGET/osheets.Count) 65cdf0e10cSrcweir Else 66cdf0e10cSrcweir sStatustext = ReplaceString(sStsRELSHEETRANGES,Str(i+1),"%1Number%1") 67cdf0e10cSrcweir sStatustext = ReplaceString(sStatusText,oSheets.Count,"%2TotPageCount%2") 68cdf0e10cSrcweir SetStatusLineText(sStatusText) 69cdf0e10cSrcweir End If 70cdf0e10cSrcweir oRanges = osheet.CellFormatRanges.createEnumeration 71cdf0e10cSrcweir MaxIndex = AddSheetRanges(oRanges, MaxIndex, oSheet, bAutopilot) 72cdf0e10cSrcweir Next i 73cdf0e10cSrcweir Else 74cdf0e10cSrcweir If Not bAutoPilot Then 75cdf0e10cSrcweir SetStatusLineText(sStsRELRANGES) 76cdf0e10cSrcweir ' cellranges already defined 77cdf0e10cSrcweir For i = 0 To Ubound(RangeList()) 78cdf0e10cSrcweir If RangeList(i) <> "" Then 79cdf0e10cSrcweir AddSingleItemToListBox(DialogModel.lstSelection, RangeList(i)) 80cdf0e10cSrcweir End If 81cdf0e10cSrcweir Next 82cdf0e10cSrcweir End If 83cdf0e10cSrcweir End If 84cdf0e10cSrcweir If MaxIndex > -1 Then 85cdf0e10cSrcweir ReDim Preserve RangeList(MaxIndex) 86cdf0e10cSrcweir Else 87cdf0e10cSrcweir ReDim RangeList() 88cdf0e10cSrcweir End If 89cdf0e10cSrcweir Rangeindex = MaxIndex 90cdf0e10cSrcweirEnd Sub 91*b53bcc32SMatthias Seidel 92*b53bcc32SMatthias Seidel 93cdf0e10cSrcweirFunction AddSheetRanges(oRanges as Object, r as Integer, oSheet as Object, bAutopilot) 94cdf0e10cSrcweirDim RangeName as String 95cdf0e10cSrcweirDim AddtoList as Boolean 96cdf0e10cSrcweirDim iCurStep as Integer 97cdf0e10cSrcweirDim MaxIndex as Integer 98cdf0e10cSrcweir iCurStep = DialogModel.Step 99cdf0e10cSrcweir While oRanges.hasMoreElements 100cdf0e10cSrcweir oRange = oRanges.NextElement 101cdf0e10cSrcweir AddToList = CheckFormatType(oRange) 102cdf0e10cSrcweir If AddToList Then 103cdf0e10cSrcweir RangeName = RetrieveRangeNamefromAddress(oRange) 104cdf0e10cSrcweir TotCellCount = TotCellCount + CountRangeCells(oRange) 105cdf0e10cSrcweir If Not bAutoPilot Then 106cdf0e10cSrcweir AddSingleItemToListbox(DialogModel.lstSelection, RangeName) 107cdf0e10cSrcweir End If 108cdf0e10cSrcweir ' The Ranges are only passed to an Array when the whole Document is the basis 109cdf0e10cSrcweir ' Redimension the RangeList Array if necessary 110cdf0e10cSrcweir MaxIndex = Ubound(RangeList()) 111cdf0e10cSrcweir r = r + 1 112cdf0e10cSrcweir If r > MaxIndex Then 113cdf0e10cSrcweir MaxIndex = MaxIndex + SBRANGEUBOUND 114cdf0e10cSrcweir ReDim Preserve RangeList(MaxIndex) 115cdf0e10cSrcweir End If 116cdf0e10cSrcweir RangeList(r) = RangeName 117cdf0e10cSrcweir End If 118cdf0e10cSrcweir Wend 119cdf0e10cSrcweir AddSheetRanges = r 120cdf0e10cSrcweirEnd Function 121cdf0e10cSrcweir 122cdf0e10cSrcweir 123cdf0e10cSrcweir' adds a section to the collection 124cdf0e10cSrcweirSub SelectRange() 125cdf0e10cSrcweirDim i as Integer 126cdf0e10cSrcweirDim RangeName as String 127cdf0e10cSrcweirDim SelItem as String 128cdf0e10cSrcweirDim CurRange as String 129cdf0e10cSrcweirDim SheetRangeName as String 130cdf0e10cSrcweirDim DescriptionList() as String 131cdf0e10cSrcweirDim MaxRangeIndex as Integer 132cdf0e10cSrcweirDim StatusValue as Integer 133cdf0e10cSrcweir StatusValue = 0 134cdf0e10cSrcweir MaxRangeIndex = Ubound(SelRangeList()) 135cdf0e10cSrcweir CurSheetName = oSheet.Name 136cdf0e10cSrcweir For i = 0 To MaxRangeIndex 137cdf0e10cSrcweir SelItem = SelRangeList(i) 138cdf0e10cSrcweir ' Is the Range already included in the collection? 139cdf0e10cSrcweir oRange = RetrieveRangeoutOfRangename(SelItem) 140cdf0e10cSrcweir TotCellCount = TotCellCount + CountRangeCells(oRange) 141cdf0e10cSrcweir DescriptionList() = ArrayOutofString(SelItem,".",1) 142cdf0e10cSrcweir SheetRangeName = DeleteStr(DescriptionList(0),"'") 143cdf0e10cSrcweir If SheetRangeName = CurSheetName Then 144cdf0e10cSrcweir oSelRanges.InsertbyName("",oRange) 145cdf0e10cSrcweir End If 146cdf0e10cSrcweir IncreaseStatusValue(SBRELGET/MaxRangeIndex) 147cdf0e10cSrcweir Next i 148cdf0e10cSrcweirEnd Sub 149cdf0e10cSrcweir 150cdf0e10cSrcweir 151cdf0e10cSrcweirSub ConvertThehardWay(ListboxList(), SwitchFormat as Boolean, bRemove as Boolean) 152cdf0e10cSrcweirDim i as Integer 153cdf0e10cSrcweirDim AddCells as Long 154cdf0e10cSrcweirDim OldStatusValue as Single 155cdf0e10cSrcweirDim RangeName as String 156cdf0e10cSrcweirDim LastIndex as Integer 157cdf0e10cSrcweirDim oSelListbox as Object 158cdf0e10cSrcweir 159cdf0e10cSrcweir oSelListbox = DialogConvert.GetControl("lstSelection") 160cdf0e10cSrcweir Lastindex = Ubound(ListboxList()) 161cdf0e10cSrcweir If TotCellCount > 0 Then 162cdf0e10cSrcweir OldStatusValue = StatusValue 163cdf0e10cSrcweir ' hard format 164cdf0e10cSrcweir For i = 0 To LastIndex 165cdf0e10cSrcweir RangeName = ListboxList(i) 166cdf0e10cSrcweir oRange = RetrieveRangeoutofRangeName(RangeName) 167cdf0e10cSrcweir ConvertCellCurrencies(oRange) 168cdf0e10cSrcweir If bRemove Then 169cdf0e10cSrcweir If oSelRanges.HasbyName(RangeName) Then 170cdf0e10cSrcweir oSelRanges.RemovebyName(RangeName) 171*b53bcc32SMatthias Seidel oDocument.CurrentController.Select(oSelRanges) 172cdf0e10cSrcweir End If 173cdf0e10cSrcweir End If 174cdf0e10cSrcweir If SwitchFormat Then 175cdf0e10cSrcweir If oRange.getPropertyState("NumberFormat") <> 1 Then 176cdf0e10cSrcweir ' Range is hard formatted 177cdf0e10cSrcweir SwitchNumberFormat(oRange, oFormats, sEuroSign) 178cdf0e10cSrcweir End If 179cdf0e10cSrcweir Else 180cdf0e10cSrcweir SwitchNumberFormat(oRange, oFormats, sEuroSign) 181cdf0e10cSrcweir End If 182cdf0e10cSrcweir AddCells = CountRangeCells(oRange) 183cdf0e10cSrcweir CurCellCount = AddCells 184cdf0e10cSrcweir IncreaseStatusValue((CurCellCount/TotCellCount)*(100-OldStatusValue)) 185cdf0e10cSrcweir If bRemove Then 186cdf0e10cSrcweir RemoveListBoxItemByName(oSelListbox.Model,Rangename) 187cdf0e10cSrcweir End If 188cdf0e10cSrcweir Next 189cdf0e10cSrcweir End If 190cdf0e10cSrcweirEnd Sub 191cdf0e10cSrcweir 192cdf0e10cSrcweir 193cdf0e10cSrcweirSub ConvertCellCurrencies(oRange as Object) 194cdf0e10cSrcweirDim oValues as Object 195cdf0e10cSrcweirDim oCells as Object 196cdf0e10cSrcweirDim oCell as Object 197*b53bcc32SMatthias Seidel oValues = oRange.queryContentCells(com.sun.star.sheet.CellFlags.VALUE) 198cdf0e10cSrcweir If (oValues.Count > 0) Then 199cdf0e10cSrcweir oCells = oValues.Cells.createEnumeration 200cdf0e10cSrcweir While oCells.hasMoreElements 201cdf0e10cSrcweir oCell = oCells.nextElement 202cdf0e10cSrcweir ModifyObjectValuewithCurrFactor(oCell) 203cdf0e10cSrcweir Wend 204cdf0e10cSrcweir End If 205cdf0e10cSrcweirEnd Sub 206cdf0e10cSrcweir 207cdf0e10cSrcweir 208cdf0e10cSrcweirSub ModifyObjectValuewithCurrFactor(oDocObject as Object) 209cdf0e10cSrcweirDim oDocObjectValue as double 210cdf0e10cSrcweir oDocObjectValue = oDocObject.Value 211cdf0e10cSrcweir oDocObject.Value = Round(oDocObjectValue/CurrFactor, 2) 212cdf0e10cSrcweirEnd Sub 213cdf0e10cSrcweir 214cdf0e10cSrcweir 215cdf0e10cSrcweirFunction CheckIfRangeisCurrency(FormatObject as Object) 216cdf0e10cSrcweirDim oFormatofObject() as Object 217cdf0e10cSrcweir ' Retrieve the Format of the Object 218cdf0e10cSrcweir On Local Error GoTo NOKEY 219cdf0e10cSrcweir oFormatofObject() = oFormats.getByKey(FormatObject.NumberFormat) 220*b53bcc32SMatthias Seidel On Local Error GoTo 0 221cdf0e10cSrcweir CheckIfRangeIsCurrency = INT(oFormatofObject.Type) AND com.sun.star.util.NumberFormat.CURRENCY 222cdf0e10cSrcweir Exit Function 223cdf0e10cSrcweirNOKEY: 224cdf0e10cSrcweir CheckIfRangeisCurrency = False 225cdf0e10cSrcweir Resume CLERROR 226cdf0e10cSrcweir CLERROR: 227cdf0e10cSrcweirEnd Function 228cdf0e10cSrcweir 229cdf0e10cSrcweir 230cdf0e10cSrcweirFunction CountColumnsForRow(IndexArray() as String, Row as Integer) 231cdf0e10cSrcweirDim i as Integer 232cdf0e10cSrcweirDim NoNulls as Boolean 233cdf0e10cSrcweir For i = 1 To Ubound(IndexArray,2) 234cdf0e10cSrcweir If IndexArray(Row,i)= "" Then 235cdf0e10cSrcweir NoNulls = False 236cdf0e10cSrcweir Exit For 237cdf0e10cSrcweir End If 238cdf0e10cSrcweir Next 239cdf0e10cSrcweir CountColumnsForRow = i 240cdf0e10cSrcweirEnd Function 241cdf0e10cSrcweir 242cdf0e10cSrcweir 243cdf0e10cSrcweirFunction CountRangeCells(oRange as Object) As Long 244cdf0e10cSrcweirDim oRangeAddress as Object 245cdf0e10cSrcweirDim LocCellCount as Long 246cdf0e10cSrcweir oRangeAddress = oRange.RangeAddress 247cdf0e10cSrcweir LocCellCount = (oRangeAddress.EndColumn - oRangeAddress.StartColumn + 1) * (oRangeAddress.EndRow - oRangeAddress.StartRow + 1) 248cdf0e10cSrcweir CountRangeCells = LocCellCount 2493e02b54dSAndrew RistEnd Function</script:module> 250