Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / wizards / source / depot / tools.xba
blobdaadf498899bf5959a2e35fff31cb94fe209ea1b
1 <?xml version="1.0" encoding="UTF-8"?>
2 <!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
3 <!--
4 * This file is part of the LibreOffice project.
6 * This Source Code Form is subject to the terms of the Mozilla Public
7 * License, v. 2.0. If a copy of the MPL was not distributed with this
8 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 * This file incorporates work covered by the following license notice:
12 * Licensed to the Apache Software Foundation (ASF) under one or more
13 * contributor license agreements. See the NOTICE file distributed
14 * with this work for additional information regarding copyright
15 * ownership. The ASF licenses this file to you under the Apache
16 * License, Version 2.0 (the "License"); you may not use this file
17 * except in compliance with the License. You may obtain a copy of
18 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 -->
20 <script:module xmlns:script="http://openoffice.org/2000/script" script:name="tools" script:language="StarBasic">REM ***** BASIC *****
21 Option Explicit
23 Sub RemoveSheet()
24 If oSheets.HasbyName(&quot;Link&quot;) then
25 oSheets.RemovebyName(&quot;Link&quot;)
26 End If
27 End Sub
30 Sub InitializeStatusLine(StatusText as String, MaxValue as Integer, FirstValue as Integer)
31 oStatusline = oDocument.GetCurrentController.GetFrame.CreateStatusIndicator()
32 oStatusLine.Start(StatusText, MaxValue)
33 oStatusline.SetValue(FirstValue)
34 End Sub
37 Sub MakeRangeVisible(oSheet as Object, RangeName as String, BIsVisible as Boolean)
38 Dim oRangeAddress, oColumns as Object
39 Dim i, iStartColumn, iEndColumn as Integer
40 oRangeAddress = oSheet.GetCellRangeByName(RangeName).RangeAddress
41 iStartColumn = oRangeAddress.StartColumn
42 iEndColumn = oRangeAddress.EndColumn
43 oColumns = oSheet.Columns
44 For i = iStartColumn To iEndColumn
45 oSheet.Columns(i).IsVisible = bIsVisible
46 Next i
47 End Sub
50 Function GetRowIndex(oSheet as Object, RowName as String)
51 Dim oRange as Object
52 oRange = oSheet.GetCellRangeByName(RowName)
53 GetRowIndex = oRange.RangeAddress.StartRow
54 End Function
57 Function GetTransactionCount(iStartRow as Integer)
58 Dim iEndRow as Integer
59 iStartRow = GetRowIndex(oMovementSheet, &quot;ColumnsToHide&quot;)
60 iEndRow = GetRowIndex(oMovementSheet, &quot;HiddenRow3&quot; )
61 GetTransactionCount = iEndRow -iStartRow - 2
62 End Function
65 Function GetStocksCount(iStartRow as Integer)
66 Dim iEndRow as Integer
67 iStartRow = GetRowIndex(oFirstSheet, &quot;HiddenRow1&quot;)
68 iEndRow = GetRowIndex(oFirstSheet, &quot;HiddenRow2&quot;)
69 GetStocksCount = iEndRow -iStartRow - 1
70 End Function
73 Function FillListbox(ListboxControl as Object, MsgTitle as String, bShowMessage) as Boolean
74 Dim i, StocksCount as Integer
75 Dim iStartRow as Integer
76 Dim oCell as Object
77 &apos; Add stock names to empty list box
78 StocksCount = GetStocksCount(iStartRow)
79 If StocksCount &gt; 0 Then
80 ListboxControl.Model.StringItemList() = NullList()
81 For i = 1 To StocksCount
82 oCell = oFirstSheet.GetCellByPosition(SBCOLUMNNAME1,iStartRow + i)
83 ListboxControl.AddItem(oCell.String, i-1)
84 Next
85 FillListbox() = True
86 Else
87 If bShowMessage Then
88 Msgbox(sInsertStockName, 16, MsgTitle)
89 FillListbox() = False
90 End If
91 End If
92 End Function
95 Sub CellValuetoControl(oSheet, oControl as Object, CellName as String)
96 Dim oCell as Object
97 Dim StringValue
98 oCell = GetCellByName(oSheet, CellName)
99 If oControl.PropertySetInfo.HasPropertyByName(&quot;EffectiveValue&quot;) Then
100 oControl.EffectiveValue = oCell.Value
101 Else
102 oControl.Value = oCell.Value
103 End If
104 &apos; If oCell.FormulaResultType = 1 Then
105 &apos; StringValue = oNumberFormatter.GetInputString(oCell.NumberFormat, oCell.Value)
106 &apos; oControl.Text = DeleteStr(StringValue, &quot;%&quot;)
107 &apos; Else
108 &apos; oControl.Text = oCell.String
109 &apos; End If
110 End Sub
113 Sub RemoveStockRows(oSheet as Object, iStartRow, RowCount as Integer)
114 If RowCount &gt; 0 Then
115 oSheet.Rows.RemoveByIndex(iStartRow, RowCount)
116 End If
117 End Sub
120 Sub AddValueToCellContent(iCellCol, iCellRow as Integer, AddValue)
121 Dim oCell as Object
122 Dim OldValue
123 oCell = oMovementSheet.GetCellByPosition(iCellCol, iCellRow)
124 OldValue = oCell.Value
125 oCell.Value = OldValue + AddValue
126 End Sub
129 Sub CheckInputDate(aEvent as Object)
130 Dim oRefDialog as Object
131 Dim oRefModel as Object
132 Dim oDateModel as Object
133 oDateModel = aEvent.Source.Model
134 oRefModel = DlgReference.GetControl(&quot;cmdGoOn&quot;).Model
135 oRefModel.Enabled = oDateModel.Date &lt;&gt; 0
136 End Sub
140 &apos; Updates the cell with the CurrentValue after checking if the
141 &apos; Newdate is later than the one that is referred to in the annotation
142 &apos; of the cell
143 Sub InsertCurrentValue(CurValue as Double, iRow as Integer, Newdate as Date)
144 Dim oCell as Object
145 Dim OldDate as Date
146 oCell = oFirstSheet.GetCellByPosition(SBCOLUMNRATE1, iRow)
147 OldDate = CDate(oCell.Annotation.Text.String)
148 If NewDate &gt;= OldDate Then
149 oCell.SetValue(CurValue)
150 oCell.Annotation.Text.SetString(CStr(NewDate))
151 End If
152 End Sub
155 Sub SplitCellValue(oSheet, FirstNumber, SecondNumber, iCol, iRow, NoteText)
156 Dim oCell as Object
157 Dim OldValue
158 oCell = oSheet.GetCellByPosition(iCol, iRow)
159 OldValue = oCell.Value
160 oCell.Value = OldValue * FirstNumber / SecondNumber
161 If NoteText &lt;&gt; &quot;&quot; Then
162 oCell.Annotation.SetString(NoteText)
163 End If
164 End Sub
167 Function GetStockRowIndex(ByVal Stockname) as Integer
168 Dim i, StocksCount as Integer
169 Dim iStartRow as Integer
170 Dim oCell as Object
171 StocksCount = GetStocksCount(iStartRow)
172 For i = 1 To StocksCount
173 oCell = oFirstSheet.GetCellByPosition(SBCOLUMNNAME1,iStartRow + i)
174 If oCell.String = Stockname Then
175 GetStockRowIndex = iStartRow + i
176 Exit Function
177 End If
178 Next
179 GetStockRowIndex = -1
180 End Function
183 Function GetStockID(StockName as String, Optional iFirstRow as Integer) as String
184 Dim CellStockName as String
185 Dim i as Integer
186 Dim iCount as Integer
187 Dim iLastRow as Integer
188 If IsMissing(iFirstRow) Then
189 iFirstRow = GetRowIndex(oFirstSheet, &quot;HiddenRow1&quot;)
190 End If
191 iCount = GetStocksCount(iFirstRow)
192 iLastRow = iFirstRow + iCount
193 For i = iFirstRow To iLastRow
194 CellStockName = oFirstSheet.GetCellByPosition(SBCOLUMNNAME1, i).String
195 If CellStockname = StockName Then
196 Exit For
197 End If
198 Next i
199 If i &gt; iLastRow Then
200 GetStockID() = &quot;&quot;
201 Else
202 If Not IsMissing(iFirstRow) Then
203 iFirstRow = i
204 End If
205 GetStockID() = oFirstSheet.GetCellByPosition(SBCOLUMNID1, i).String
206 End If
207 End Function
210 Function CheckDocLocale(LocLanguage as String, LocCountry as String)
211 Dim bIsDocLanguage as Boolean
212 Dim bIsDocCountry as Boolean
213 bIsDocLanguage = Instr(1, LocLanguage, sDocLanguage, SBBINARY) &lt;&gt; 0
214 bIsDocCountry = Instr(1, LocCountry, sDocCountry, SBBINARY) &lt;&gt; 0 OR SDocCountry = &quot;&quot;
215 CheckDocLocale = (bIsDocLanguage And bIsDocCountry)
216 End Function
217 </script:module>