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=
"Common" script:
language=
"StarBasic"> REM ***** BASIC *****
4 Public DialogModel as Object
5 Public DialogConvert as Object
6 Public DialogPassword as Object
7 Public PasswordModel as Object
9 Sub RetrieveDocumentObjects()
10 CurMimeType = Tools.GetDocumentType(oDocument)
11 If Instr(
1, CurMimeType,
"calc
")
<> 0 Then
12 oSheets = oDocument.Sheets
13 oSheet = oDocument.Sheets.GetbyIndex(
0)
14 oAddressRanges = oDocument.createInstance(
"com.sun.star.sheet.SheetCellRanges
")
16 ' Retrieve the indices for the cellformatations
17 oFormats = oDocument.NumberFormats
22 ' If Not DocDisposed Then
23 ' ReprotectSheets()
25 If DialogModel.Step =
3 And (Not bCancelTask) Then
26 If Msgbox(sMsgCancelConversion,
36, sMsgCancelTitle) =
6 Then
28 DialogConvert.EndExecute
33 DialogConvert.EndExecute()
38 Function ConvertDocument()
40 ' DocDisposed = True
41 InitializeProgressbar()
42 If Instr(
1, CurMimeType,
"calc
")
<> 0 Then
43 bDocHasProtectedSheets = CheckSheetProtection(oSheets)
44 If bDocHasProtectedSheets Then
45 bDocHasProtectedSheets = UnprotectSheetsWithPassword(oSheets, bDoUnProtect)
47 If Not bDocHasProtectedSheets Then
48 If Not bRangeListDefined Then
50 CreateRangeEnumeration(True)
52 IncreaseStatusvalue(SBRelGet/
3)
54 RangeIndex = Ubound(RangeList())
55 If RangeIndex
> -
1 Then
56 ConvertThehardWay(RangeList(), True, False)
57 MakeStyleEnumeration(True)
58 oDocument.calculateAll()
61 bRangeListDefined = False
64 DialogModel.ProgressBar.ProgressValue =
10 ' oStatusline.SetValue(
10)
66 DialogModel.ProgressBar.ProgressValue =
80 ' oStatusline.SetValue(
80)
74 Sub SwitchNumberFormat(oObject as Object, oFormats as object)
75 Dim nFormatLanguage as Integer
76 Dim nFormatDecimals as Integer
77 Dim nFormatLeading as Integer
78 Dim bFormatLeading as Integer
79 Dim bFormatNegRed as Integer
80 Dim bFormatThousands as Integer
83 Dim iNumberFormat as Long
84 Dim AddToList as Boolean
85 Dim sOldCurrSymbol as String
86 On Local Error Resume Next
87 iNumberFormat = oObject.NumberFormat
88 On Local Error GoTo NOKEY
89 aFormat() = oFormats.getByKey(iNumberFormat)
91 sOldCurrSymbol = aFormat.CurrencySymbol
92 If sOldCurrSymbol = CurrValue(CurrIndex,
5) Then
93 aSimpleStr =
"0 [$EUR]
"
95 aSimpleStr =
"0 [$
" & sEuroSign
& aFormat.CurrencyExtension
& "]
"
98 nSimpleKey = Numberformat(oFormats, aSimpleStr, oLocale)
99 ' set new Currency format with according settings
101 nFormatLeading = aFormat.LeadingZeros
102 bFormatNegRed = aFormat.NegativeRed
103 bFormatThousands = aFormat.ThousandsSeparator
104 aNewStr = oFormats.generateFormat( nSimpleKey, aFormat.Locale, bFormatThousands, bFormatNegRed, nFormatDecimals, nFormatLeading)
105 oObject.NumberFormat = Numberformat(oFormats, aNewStr, aFormat.Locale)
107 If Err
<> 0 Then
114 Function Numberformat( oFormats as Object, aFormatStr as String, oLocale as Object)
118 nRetKey = oFormats.queryKey( aFormatStr, oLocale, True )
122 nRetKey = oFormats.addNew( aFormatStr, oLocale )
123 If nRetKey = -
1 Then nRetKey =
0
125 Numberformat = nRetKey
129 Function CheckFormatType( FormatObject as object)
131 Dim LocCurrIndex as Integer
132 Dim nFormatFormatString as String
133 Dim FormatLangID as Integer
134 Dim sFormatCurrExt as String
135 Dim oFormatofObject() as Object
137 ' Retrieve the Format of the Object
138 On Local Error GoTo NOKEY
139 oFormatofObject = oFormats.getByKey(FormatObject.NumberFormat)
140 On Local Error GoTo
0
141 If NOT INT(oFormatofObject.Type) AND com.sun.star.util.NumberFormat.CURRENCY Then
142 CheckFormatType = False
145 If FieldinArray(CurrSymbolList(),
2,oFormatofObject.CurrencySymbol) Then
146 ' If the Currencysymbol of the object ist the one needed, then check the Currency extension
147 sFormatCurrExt = oFormatofObject.CurrencyExtension
149 If FieldInList(CurExtension(),
2,sFormatCurrExt) Then
150 ' The Currency - extension also fits
151 CheckFormatType = True
153 ' The Currency - symbol is Euro-conforming (like
'DEM
'), so there is no Currency-Extension
154 CheckFormatType = oFormatofObject.CurrencySymbol = CurrsymbolList(
2)
157 ' The Currency Symbol of the object is not the desired one
158 If oFormatofObject.CurrencySymbol =
"" Then
159 ' Format is
"automatic
"
160 CheckFormatType = CheckLocale(oFormatofObject.Locale)
162 CheckFormatType = False
167 If Err
<> 0 Then
168 CheckFormatType = False
175 Sub StartConversion()
177 Select Case DialogModel.Step
179 If DialogModel.chkComplete.State =
1 Then
180 ConvertWholeDocument()
182 ConvertRangesorStylesofDocument()
186 If InitializeThirdStep() Then
191 DialogConvert.EndExecute()
196 Sub IncreaseStatusValue(AddStatusValue as Integer)
197 StatusValue = Int(StatusValue + AddStatusValue)
198 If DialogModel.Step =
3 Then
199 DialogModel.ProgressBar.ProgressValue = StatusValue
201 oStatusline.SetValue(StatusValue)
207 Dim AddtoList as Boolean
209 Dim OldCurrIndex as Integer
210 bRangeListDefined = False
211 OldCurrIndex = CurrIndex
212 CurrIndex = DialogModel.lstCurrencies.SelectedItems(
0)
213 If OldCurrIndex
<> CurrIndex Then
214 InitializeCurrencyValues(CurrIndex)
215 CurExtension(
0) = LangIDValue(CurrIndex,
0,
2)
216 CurExtension(
1) = LangIDValue(CurrIndex,
1,
2)
217 CurExtension(
2) = LangIDValue(CurrIndex,
2,
2)
218 If DialogModel.Step =
1 Then
219 EnableStep1DialogControls(False,False, False)
220 If DialogModel.optCellTemplates.State =
1 Then
221 EnableStep1DialogControls(False, False, False)
222 CreateStyleEnumeration()
223 ElseIf ((DialogModel.optSheetRanges.State =
1) OR (DialogModel.optDocRanges.State =
1)) AND (DialogModel.Step =
1) Then
224 CreateRangeEnumeration(False)
225 If Ubound(RangeList()) = -
1 Then
226 DialogModel.lstSelection.StringItemList() = NullList()
228 ElseIf DialogModel.optSelRange.State=
1 Then
229 'Preselected Range
231 EnableStep1DialogControls(True, True, True)
232 ElseIf DialogModel.Step =
2 Then
233 EnableStep2DialogControls(True)
239 Sub FillUpCurrencyListbox()
241 Dim MaxIndex as Integer
242 MaxIndex = Ubound(CurrValue(),
1)
243 Dim LocList(MaxIndex) as String
244 For i =
0 To MaxIndex
245 LocList(i) = CurrValue(i,
0)
247 DialogModel.lstCurrencies.StringItemList() = LocList()
248 If CurrIndex
> -
1 Then
249 SelectListboxItem(DialogModel.lstCurrencies, CurrIndex)
254 Sub InitializeProgressbar()
256 If Not IsNull(oStatusLine) Then
257 oStatusline.Start(sStsPROGRESS,
100)
259 DialogModel.ProgressBar.ProgressValue =
0
266 If Not IsNull(oStatusLine) Then
269 DialogModel.ProgressBar.ProgressValue =
100