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