1 <?xml version=
"1.0" encoding=
"UTF-8"?>
2 <!DOCTYPE script:module PUBLIC
"-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
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 .
20 <script:module xmlns:
script=
"http://openoffice.org/2000/script" script:
name=
"tools" script:
language=
"StarBasic">REM ***** BASIC *****
24 If oSheets.HasbyName(
"Link
") then
25 oSheets.RemovebyName(
"Link
")
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)
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
50 Function GetRowIndex(oSheet as Object, RowName as String)
52 oRange = oSheet.GetCellRangeByName(RowName)
53 GetRowIndex = oRange.RangeAddress.StartRow
57 Function GetTransactionCount(iStartRow as Integer)
58 Dim iEndRow as Integer
59 iStartRow = GetRowIndex(oMovementSheet,
"ColumnsToHide
")
60 iEndRow = GetRowIndex(oMovementSheet,
"HiddenRow3
" )
61 GetTransactionCount = iEndRow -iStartRow -
2
65 Function GetStocksCount(iStartRow as Integer)
66 Dim iEndRow as Integer
67 iStartRow = GetRowIndex(oFirstSheet,
"HiddenRow1
")
68 iEndRow = GetRowIndex(oFirstSheet,
"HiddenRow2
")
69 GetStocksCount = iEndRow -iStartRow -
1
73 Function FillListbox(ListboxControl as Object, MsgTitle as String, bShowMessage) as Boolean
74 Dim i, StocksCount as Integer
75 Dim iStartRow as Integer
77 ' Add stock names to empty list box
78 StocksCount = GetStocksCount(iStartRow)
79 If StocksCount
> 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)
88 Msgbox(sInsertStockName,
16, MsgTitle)
95 Sub CellValuetoControl(oSheet, oControl as Object, CellName as String)
98 oCell = GetCellByName(oSheet, CellName)
99 If oControl.PropertySetInfo.HasPropertyByName(
"EffectiveValue
") Then
100 oControl.EffectiveValue = oCell.Value
102 oControl.Value = oCell.Value
104 ' If oCell.FormulaResultType =
1 Then
105 ' StringValue = oNumberFormatter.GetInputString(oCell.NumberFormat, oCell.Value)
106 ' oControl.Text = DeleteStr(StringValue,
"%
")
108 ' oControl.Text = oCell.String
113 Sub RemoveStockRows(oSheet as Object, iStartRow, RowCount as Integer)
114 If RowCount
> 0 Then
115 oSheet.Rows.RemoveByIndex(iStartRow, RowCount)
120 Sub AddValueToCellContent(iCellCol, iCellRow as Integer, AddValue)
123 oCell = oMovementSheet.GetCellByPosition(iCellCol, iCellRow)
124 OldValue = oCell.Value
125 oCell.Value = OldValue + AddValue
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(
"cmdGoOn
").Model
135 oRefModel.Enabled = oDateModel.Date
<> 0
140 ' Updates the cell with the CurrentValue after checking if the
141 ' Newdate is later than the one that is referred to in the annotation
143 Sub InsertCurrentValue(CurValue as Double, iRow as Integer, Newdate as Date)
146 oCell = oFirstSheet.GetCellByPosition(SBCOLUMNRATE1, iRow)
147 OldDate = CDate(oCell.Annotation.Text.String)
148 If NewDate
>= OldDate Then
149 oCell.SetValue(CurValue)
150 oCell.Annotation.Text.SetString(CStr(NewDate))
155 Sub SplitCellValue(oSheet, FirstNumber, SecondNumber, iCol, iRow, NoteText)
158 oCell = oSheet.GetCellByPosition(iCol, iRow)
159 OldValue = oCell.Value
160 oCell.Value = OldValue * FirstNumber / SecondNumber
161 If NoteText
<> "" Then
162 oCell.Annotation.SetString(NoteText)
167 Function GetStockRowIndex(ByVal Stockname) as Integer
168 Dim i, StocksCount as Integer
169 Dim iStartRow as Integer
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
179 GetStockRowIndex = -
1
183 Function GetStockID(StockName as String, Optional iFirstRow as Integer) as String
184 Dim CellStockName as String
186 Dim iCount as Integer
187 Dim iLastRow as Integer
188 If IsMissing(iFirstRow) Then
189 iFirstRow = GetRowIndex(oFirstSheet,
"HiddenRow1
")
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
199 If i
> iLastRow Then
200 GetStockID() =
""
202 If Not IsMissing(iFirstRow) Then
205 GetStockID() = oFirstSheet.GetCellByPosition(SBCOLUMNID1, i).String
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)
<> 0
214 bIsDocCountry = Instr(
1, LocCountry, sDocCountry, SBBINARY)
<> 0 OR SDocCountry =
""
215 CheckDocLocale = (bIsDocLanguage And bIsDocCountry)