2001-04-23 04:46:42 -05:00
<?xml version="1.0" encoding="UTF-8"?>
2001-06-25 02:58:41 -05:00
<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
2002-01-11 06:30:59 -06:00
<script:module xmlns:script="http://openoffice.org/2000/script" script:name="Soft" script:language="StarBasic">Option Explicit
2001-04-23 04:46:42 -05:00
REM ***** BASIC *****
Sub CreateStyleEnumeration()
EmptySelection()
EmptyListbox(DialogModel.lstSelection)
CurSheetName = oDocument.CurrentController.GetActiveSheet.Name
MakeStyleEnumeration(False)
2002-09-17 07:09:36 -05:00
DialogModel.lblSelection.Label = sTEMPLATES
2001-04-23 04:46:42 -05:00
End Sub
2001-06-25 02:58:41 -05:00
Sub MakeStyleEnumeration(bAddToListbox as Boolean)
2001-04-23 04:46:42 -05:00
Dim m as integer
Dim aStyleFormat as Object
Dim Stylename as String
2001-06-25 02:58:41 -05:00
StyleIndex = -1
2001-04-23 04:46:42 -05:00
oStyles = oDocument.StyleFamilies.GetbyIndex(0)
For m = 0 To oStyles.count-1
oStyle = oStyles.GetbyIndex(m)
StyleName = oStyle.Name
2001-11-30 09:58:48 -06:00
If CheckFormatType(oStyle) Then
2001-06-25 02:58:41 -05:00
If Not bAddToListBox Then
2001-04-23 04:46:42 -05:00
AddSingleItemToListbox(DialogModel.lstSelection, Stylename)
Else
2001-06-25 02:58:41 -05:00
SwitchNumberFormat(ostyle, oFormats, sEuroSign)
2001-04-23 04:46:42 -05:00
End If
StyleIndex = StyleIndex + 1
2001-06-25 13:03:49 -05:00
If StyleIndex > Ubound(StyleRangeAssignMentList()) Then
Redim Preserve StyleRangeAssignmentList(StyleIndex)
End If
2001-06-25 02:58:41 -05:00
StyleRangeAssignmentList(StyleIndex) = "<STYLENAME>" & Stylename & "</STYLENAME>" & _
"<DEFINED>FALSE</DEFINED>" & "<RANGES></RANGES>" &_
"<CELLCOUNT>0</CELLCOUNT>" &_
"<SELECTED>FALSE</SELECTED>"
2001-04-23 04:46:42 -05:00
End If
Next m
2001-06-25 02:58:41 -05:00
If StyleIndex > -1 Then
Redim Preserve StyleRangeAssignmentList(StyleIndex)
Else
ReDim StyleRangeAssignmentList()
End If
2001-04-23 04:46:42 -05:00
End Sub
2001-06-25 02:58:41 -05:00
Sub AssignRangestoStyle(StyleList(), SelList())
Dim i as Integer
Dim n as integer
2001-04-23 04:46:42 -05:00
Dim LastIndex as Integer
2001-06-25 02:58:41 -05:00
Dim CurStyleName as String
Dim AssignString as String
2001-04-23 04:46:42 -05:00
LastIndex = Ubound(StyleList())
StatusValue = 0
2002-07-11 09:36:57 -05:00
SetStatusLineText(sStsRELRANGES)
2001-04-23 04:46:42 -05:00
For i = 0 To LastIndex
CurStyleName = StyleList(i)
2001-06-25 02:58:41 -05:00
n = PartStringInArray(StyleRangeAssignmentList(), CurStyleName, 0)
AssignString = StyleRangeAssignmentlist(n)
If IndexInArray(CurStyleName, SelList()) <> -1 Then
' Style is selected
If FindPartString(AssignString, "<DEFINED>", "</DEFINED>", 1) = "FALSE" Then
AssignString = ReplaceString(AssignString, "<SELECTED>TRUE</SELECTED>", "<SELECTED>FALSE</SELECTED>")
AssignCellFormatRanges(n, AssignString, CurStyleName)
2001-04-23 04:46:42 -05:00
End If
2001-06-25 02:58:41 -05:00
Else
2001-04-23 04:46:42 -05:00
' Style is not selected
2001-06-25 02:58:41 -05:00
If FindPartString(AssignString, "<SELECTED>", "</SELECTED>", 1) = "FALSE" Then
DeselectStyle(CurStyleName, n)
2001-04-23 04:46:42 -05:00
End If
End If
IncreaseStatusvalue(SBRELGET/(LastIndex+1))
Next i
2001-06-25 02:58:41 -05:00
End Sub
2001-04-23 04:46:42 -05:00
2001-06-25 02:58:41 -05:00
Sub AssignCellFormatRanges(n as Integer, AssignString as String, CurStyleName as String)
Dim oRanges() as Object
Dim oRange as Object
Dim oRangeAddress
Dim oSheet as Object
Dim StyleCellCount as Long
Dim i as Integer
Dim MaxIndex as Integer
Dim RangeString as String
Dim SheetName as String
2001-04-23 04:46:42 -05:00
Dim RangeName as String
2001-06-25 02:58:41 -05:00
Dim CellCountString as String
StyleCellCount = 0
RangeString = "<RANGES>"
MaxIndex = oSheets.Count-1
For i = 0 To MaxIndex
oSheet = oSheets(i)
SheetName = oSheet.Name
oRanges = osheet.CellFormatRanges.CreateEnumeration
While oRanges.hasMoreElements
oRange = oRanges.NextElement
If oRange.getPropertyState("NumberFormat") = 1 Then
If oRange.CellStyle = CurStyleName Then
oRangeAddress = oRange.RangeAddress
RangeName = RetrieveRangeNamefromAddress(oRange)
RangeString = RangeString & RangeName & ","
StyleCellCount = StyleCellCount + CountRangeCells(oRange)
End If
End If
Wend
Next i
If StyleCellCount > 0 Then
TotCellCount = TotCellCount + StyleCellCount
RangeString = RTrimStr(RangeString,",")
RangeString = RangeString & "</RANGES>"
CellCountString = "<CELLCOUNT>" & StyleCellCount & "</CELLCOUNT"
AssignString = ReplaceString(AssignString, RangeString,"<RANGES></RANGES>")
AssignString = ReplaceString(AssignString, CellCountString,"<CELLCOUNT>0</CELLCOUNT>")
End If
AssignString = ReplaceString(AssignString, "<DEFINED>TRUE</DEFINED>", "<DEFINED>FALSE</DEFINED>")
StyleRangeAssignmentList(n) = AssignString
End Sub
2001-04-23 04:46:42 -05:00
2001-06-25 02:58:41 -05:00
2002-09-17 07:09:36 -05:00
' deletes a styletemplate from the Collection that selects the ranges
2001-06-25 02:58:41 -05:00
Sub DeselectStyle(DeSelStyleName as String, n as Integer)
Dim i as Integer
Dim RangeName as String
Dim SelectString as String
Dim AssignString as String
Dim StyleRangeList() as String
Dim MaxIndex as Integer
SelectString ="<SELECTED>FALSE</SELECTED>"
AssignString = StyleRangeAssignmentList(n)
RangeString = FindPartString(AssignString,"<RANGES>","</RANGES>",1)
StyleRangeList() = ArrayoutofString(RangeString,",")
MaxIndex = Ubound(StyleRangeList())
For i = 0 To MaxIndex
RangeName = StyleRangeList(i)
If oSelRanges.HasbyName(RangeName) Then
2001-04-23 04:46:42 -05:00
oSelRanges.RemovebyName(RangeName)
End If
2001-06-25 02:58:41 -05:00
Next i
AssignString = ReplaceString(AssignString, "<SELECTED>FALSE</SELECTED>", "<SELECTED>TRUE</SELECTED>")
StyleRangeAssignmentList(n) = AssignString
2001-04-23 04:46:42 -05:00
End Sub
2001-06-25 02:58:41 -05:00
Function RetrieveRangeNamefromAddress(oRange as Object) as String
2001-04-23 04:46:42 -05:00
Dim Rangename as String
2001-06-25 02:58:41 -05:00
Dim oAddressRanges as Object
oAddressRanges = oDocument.createInstance("com.sun.star.sheet.SheetCellRanges")
2001-04-23 04:46:42 -05:00
oAddressRanges.InsertbyName("",oRange)
Rangename = oAddressRanges.RangeAddressesasString
2001-06-25 02:58:41 -05:00
' Msgbox "Adresse: " & oRangeAddress.StartColumn & " ; " & oRangeAddress.EndColumn & " ; " & oRangeAddress.StartRow & " ; " & oRangeAddress.EndRow & chr(13) & RangeName
' oAddressRanges.RemovebyName(RangeName)
2001-04-23 04:46:42 -05:00
RetrieveRangeNamefromAddress = Rangename
End Function
2002-09-17 07:09:36 -05:00
' creates a sheet object from an according sectionname
2001-04-23 04:46:42 -05:00
Function RetrieveSheetoutofRangeName(TableText as String)
Dim DescriptionList() as String
Dim SheetName as String
Dim MaxIndex as integer
2002-09-17 07:09:36 -05:00
' find out in which sheet the range is
2001-04-23 04:46:42 -05:00
DescriptionList() = ArrayOutofString(TableText,".",MaxIndex)
SheetName = DescriptionList(0)
SheetName = DeleteStr(SheetName,"'")
2002-09-17 07:09:36 -05:00
' set the viewcursor on this sheet
2001-04-23 04:46:42 -05:00
RetrieveSheetoutofRangeName = oSheets.GetbyName(SheetName)
End Function
2002-09-17 07:09:36 -05:00
' creates a rangeobject from an according rangename
2001-04-23 04:46:42 -05:00
Function RetrieveRangeoutofRangeName(TableText as String)
oSheet = RetrieveSheetoutofRangeName(TableText)
oRange = oSheet.GetCellRangebyName(TableText)
RetrieveRangeoutofRangeName = oRange
End Function
2001-06-25 02:58:41 -05:00
Sub ConvertTheSoftWay(StyleList(), bDeSelect as Boolean)
Dim i as Integer
Dim l as Integer
Dim s as Integer
Dim n as Integer
2001-04-23 04:46:42 -05:00
Dim CurStyleName as String
Dim RangeName as String
Dim OldStatusValue as Integer
Dim LastIndex as Integer
2001-06-25 02:58:41 -05:00
Dim oSelListbox as Object
Dim StyleRangeList() as String
Dim MaxIndex as Integer
oSelListbox = DialogConvert.GetControl("lstSelection")
2001-04-23 04:46:42 -05:00
LastIndex = Ubound(StyleList())
OldStatusValue = StatusValue
For i = 0 To LastIndex
2001-06-25 02:58:41 -05:00
CurStyleName = StyleList(i)
oStyle = oStyles.GetbyName(CurStyleName)
StyleRangeList() = GetAssignedRanges(CurStyleName, n)
MaxIndex = Ubound(StyleRangeList())
For s = 0 To MaxIndex
RangeName = StyleRangeList(s)
oRange = RetrieveRangeoutofRangeName(RangeName)
If oRange.getPropertyState("NumberFormat") = 1 Then
2002-09-17 07:09:36 -05:00
' Range is hard formatted
2001-06-25 02:58:41 -05:00
ConvertCellCurrencies(oRange)
CurCellCount = CountRangeCells(oRange)
End If
IncreaseStatusvalue((CurCellCount/TotCellCount)*(95-OldStatusValue))
If bDeSelect Then
' Note: On Problems see Bug #73157
If oSelRanges.HasbyName(RangeName) Then
oSelRanges.RemovebyName(RangeName)
oDocument.CurrentController.Select(oSelRanges)
2001-04-23 04:46:42 -05:00
End If
2001-06-25 02:58:41 -05:00
End If
Next s
2001-09-12 06:30:01 -05:00
SwitchNumberFormat(ostyle, oFormats, sEuroSign)
2001-06-25 02:58:41 -05:00
StyleRangeAssignmentList(n) = ""
l = GetItemPos(oSelListBox.Model, CurStyleName)
oSelListbox.RemoveItems(l,1)
2001-04-23 04:46:42 -05:00
Next
2001-06-25 02:58:41 -05:00
End Sub
Function GetAssignedRanges(CurStyleName as String, n as Integer)
Dim StyleRangeList() as String
Dim RangeString as String
Dim AssignString as String
n = PartStringInArray(StyleRangeAssignmentList(), CurStyleName, 0)
If n <> -1 Then
AssignString = StyleRangeAssignmentList(n)
RangeString = FindPartString(AssignString,"<RANGES>", "</RANGES>",1)
If RangeString <> "" Then
StyleRangeList() = ArrayoutofString(RangeString,",")
End If
End If
GetAssignedRanges() = StyleRangeList()
2001-10-31 06:33:17 -06:00
End Function</script:module>