home *** CD-ROM | disk | FTP | other *** search
/ Kompuutteri Kaikille K-CD 2002 #3 / K-CD_2002-03.iso / OpenOffice / f_0259 / Hard.xba < prev    next >
Extensible Markup Language  |  2001-09-12  |  8KB  |  234 lines

  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  *****
  4. Option Explicit
  5. 'ToDo: W├â┬ñhrung wechseln und dann sehen, ob die Listbox mit den neuen Ranges aufgefrischt wird
  6.  
  7.  
  8. Sub CreateRangeList()
  9. Dim MaxIndex as Integer
  10.     MaxIndex = -1
  11.     EnableStep1DialogControls(False, False, False)
  12.     EmptySelection()
  13.     DialogModel.lblSelection.Label = sCURRRANGES      '"W├ñhrungsbereiche:"
  14.     EmptyListbox(DialogModel.lstSelection)
  15.     oDocument.CurrentController.Select(oSelRanges)
  16.     If (DialogModel.optSheetRanges.State = 1) AND (DialogModel.chkComplete.State <> 1) Then
  17.         ' Ist das Sheet Grundlage f├╝r die Bearbeitung?
  18.         oStatusline.SetText(sStsRELRANGES)                '"Erfassung der relevanten Bereiche..."
  19.         osheet = oDocument.CurrentController.GetActiveSheet
  20.         oRanges = osheet.CellFormatRanges.createEnumeration()
  21.         MaxIndex = AddSheetRanges(oRanges, MaxIndex, oSheet, False)
  22.         If MaxIndex > -1 Then
  23.             ReDim Preserve RangeList(MaxIndex,1)
  24.         End If
  25.     Else
  26.         CreateRangeEnumeration(False)
  27.         bRangeListDefined = True
  28.     End If
  29.     EnableStep1DialogControls(True, True, True)
  30.     oStatusline.SetText("")
  31. End Sub
  32.  
  33.  
  34. Sub CreateRangeEnumeration(bAutopilot as Boolean)
  35. Dim i as Integer
  36. Dim MaxIndex as integer
  37. Dim sStatustext as String
  38.     MaxIndex = -1
  39.     If Not bRangeListDefined Then
  40.         ' Die Ranges sind noch nicht definiert
  41.         oSheets = oDocument.Sheets
  42.         For i = 0 To oSheets.Count-1
  43.             oSheet = oSheets.GetbyIndex(i)
  44.             If bAutopilot Then
  45.                 IncreaseStatusValue(SBRELGET/osheets.Count)
  46.             Else
  47.                 sStatustext = ReplaceString(sStsRELSHEETRANGES,Str(i+1),"%1Number%1")
  48.                 sStatustext = ReplaceString(sStatusText,oSheets.Count,"%2TotPageCount%2")
  49.                 oStatusline.SetText(sStatusText)
  50.             End If
  51.             oRanges = osheet.CellFormatRanges.createEnumeration
  52.             MaxIndex = AddSheetRanges(oRanges, MaxIndex, oSheet, bAutopilot)
  53.         Next i
  54.     Else
  55.         If Not bAutoPilot Then
  56.             oStatusline.SetText(sStsRELRANGES)      '"Erfassung der relevanten Bereiche..."
  57.             ' Die Ranges sind schon definiert
  58.             For i = 0 To Ubound(RangeList(),1)
  59.                 If RangeList(i,0) <> "" AND Rangelist(i,1) = True Then
  60.                     AddSingleItemToListBox(DialogModel.lstSelection, RangeList(i))
  61.                 End If
  62.             Next
  63.         End If
  64.     End If
  65.     If MaxIndex > -1 Then
  66.         ReDim Preserve RangeList(MaxIndex,1)
  67.     End If
  68.     Rangeindex = MaxIndex
  69. End Sub
  70.     
  71.     
  72.             
  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)
  82.         If AddToList Then
  83.             RangeName = RetrieveRangeNamefromAddress(oRange)
  84.             TotCellCount = TotCellCount + CountRangeCells(oRange)
  85.             If Not bAutoPilot Then
  86.                 AddSingleItemToListbox(DialogModel.lstSelection, RangeName)
  87.             End If
  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(),1)
  91.             r = r + 1
  92.             If r > MaxIndex Then
  93.                 MaxIndex = MaxIndex + SBRANGEUBOUND
  94.                 ReDim Preserve RangeList(MaxIndex,1)
  95.             End If
  96.             RangeList(r,0) = RangeName
  97.             RangeList(r,1) = True
  98.         End If
  99.     Wend
  100.     AddSheetRanges = r
  101. End Function
  102.  
  103.  
  104. ' F├╝gt einen Bereich zur selektierten Kollektion hinzu
  105. Sub SelectRange()
  106. Dim i as Integer
  107. Dim RangeName as String
  108. Dim SelItem as String
  109. Dim CurRange as String
  110. Dim SheetRangeName as String
  111. Dim DescriptionList() as String
  112. Dim MaxRangeIndex as Integer
  113. Dim StatusValue as Integer
  114.     StatusValue = 0
  115.     MaxRangeIndex = Ubound(SelRangeList())
  116.     CurSheetName = oSheet.Name
  117.     For i = 0 To MaxRangeIndex
  118.         SelItem = SelRangeList(i)
  119.         ' Is the Range already included in the collection?
  120.         oRange = RetrieveRangeoutOfRangename(SelItem)
  121.         TotCellCount = TotCellCount + CountRangeCells(oRange)
  122.         DescriptionList() = ArrayOutofString(SelItem,".",1)
  123.         SheetRangeName = DeleteStr(DescriptionList(0),"'")
  124.         If SheetRangeName = CurSheetName Then
  125.             oSelRanges.InsertbyName("",oRange)
  126.         End If
  127.         IncreaseStatusValue(SBRELGET/MaxRangeIndex)
  128.     Next i
  129. End Sub
  130.  
  131.  
  132. Sub ConvertThehardWay(ListboxList(), SwitchFormat as Boolean, bRemove as Boolean)
  133. Dim i as Integer ' r, a
  134. Dim AddCells as Long
  135. Dim OldStatusValue as Single
  136. Dim RangeName as String
  137. Dim LastIndex as Integer
  138. Dim oSelListbox as Object
  139.  
  140.     oSelListbox = DialogConvert.GetControl("lstSelection")
  141.     Lastindex = Ubound(ListboxList())
  142.     If TotCellCount > 0 Then
  143.         OldStatusValue = StatusValue
  144.         ' Harte Formatierung
  145.         For i = 0 To LastIndex
  146.             RangeName = ListboxList(i)
  147.             oRange = RetrieveRangeoutofRangeName(RangeName)
  148.             ConvertCellCurrencies(oRange)
  149.             If bRemove Then
  150.                 If oSelRanges.HasbyName(RangeName) Then
  151.                     oSelRanges.RemovebyName(RangeName)
  152.                     oDocument.CurrentController.Select(oSelRanges)    
  153.                 End If
  154.             End If
  155.             If SwitchFormat Then
  156.                 If oRange.getPropertyState("NumberFormat") <> 1 Then
  157.                     ' Range Ist hart formatiert
  158.                     SwitchNumberFormat(oRange, oFormats, sEuroSign)' "Γé¼")
  159.                 End If
  160.             Else
  161.                 SwitchNumberFormat(oRange, oFormats, sEuroSign) '"Γé¼"
  162.             End If
  163.             AddCells = CountRangeCells(oRange)
  164.             CurCellCount = AddCells
  165.             IncreaseStatusValue((CurCellCount/TotCellCount)*(100-OldStatusValue))
  166.             If bRemove Then
  167.                 RemoveListBoxItemByName(oSelListbox.Model,Rangename)
  168.             End If
  169.         Next
  170.     End If
  171. End Sub
  172.  
  173.  
  174. Sub ConvertCellCurrencies(oRange as Object)
  175. Dim oValues as Object
  176. Dim oCells as Object
  177. Dim oCell as Object
  178.       oValues = oRange.queryContentCells(com.sun.star.sheet.CellFlags.VALUE)
  179.     If (oValues.Count > 0) Then
  180.         oCells = oValues.Cells.createEnumeration
  181.         While oCells.hasMoreElements
  182.             oCell = oCells.nextElement
  183.             ModifyObjectValuewithCurrFactor(oCell)
  184.         Wend
  185.     End If
  186. End Sub
  187.  
  188.  
  189. Sub ModifyObjectValuewithCurrFactor(oDocObject as Object)
  190. Dim oDocObjectValue as double
  191.     oDocObjectValue = oDocObject.Value
  192.     oDocObject.Value = Round(oDocObjectValue/CurrFactor, 2)
  193. End Sub
  194.  
  195.  
  196. Function CheckIfRangeisCurrency(FormatObject as Object)
  197. Dim oFormatofObject() as Object
  198.     ' Retrieve the Format of the Object
  199.     On Local Error GoTo NOKEY
  200.     oFormatofObject() = oFormats.getByKey(FormatObject.NumberFormat)
  201.     On Local Error GoTo 0            
  202.  
  203.     ' Typ und W├ñhrungssymbol des Numberformats heraussuchen
  204.     ' Todo: ├£berpr├╝fe, ob diese beiden Zeilen nicht eleganter gehen
  205.      CheckIfRangeIsCurrency = INT(oFormatofObject.Type) AND com.sun.star.util.NumberFormat.CURRENCY
  206.     Exit Function
  207. NOKEY:
  208.     CheckIfRangeisCurrency = False
  209.     Resume CLERROR
  210.     CLERROR:
  211. End Function
  212.  
  213.  
  214. Function CountColumnsForRow(IndexArray() as String, Row as Integer)
  215. Dim i as Integer
  216. Dim NoNulls as Boolean
  217.     For i = 1 To Ubound(IndexArray,2)
  218.         If IndexArray(Row,i)= "" Then
  219.             NoNulls = False
  220.             Exit For
  221.         End If
  222.     Next
  223.     CountColumnsForRow = i
  224. End Function
  225.  
  226.  
  227. Function CountRangeCells(oRange as Object) As Long
  228. Dim oRangeAddress as Object
  229. Dim LocCellCount as Long
  230.     oRangeAddress = oRange.RangeAddress
  231.     LocCellCount = (oRangeAddress.EndColumn - oRangeAddress.StartColumn + 1) * (oRangeAddress.EndRow - oRangeAddress.StartRow + 1)
  232.     CountRangeCells = LocCellCount
  233. End Function
  234. </script:module>