Download StarOffice™ Programmer`s Tutorial
Transcript
5.4.2
Updating the tables
When the current value has been determined, we have to update the table belonging
to that value. The following subroutine takes care of this.
Sub UpdateValue( oDocument As Object, sName As String,_
fDate As Double, fValue As Double )
Dim oSheets As Object, oSheet As Object
Dim nColumn As Long, nRow As Long
Dim oCursor As Object, oRanges As Object
Dim aAddress As Variant
Dim oCells As Object, oCell As Object
Dim aLanguage as New com.sun.star.lang.Locale
aLanguage.Country = "de"
aLanguage.Language = "de"
oSheets = oDocument.Sheets
sName = SheetNameFor(sName)
If oSheets.hasByName(sName) Then
oSheet = oSheets.getByName(sName)
Else
oSheet =_
oDocument.createInstance("com.sun.star.sheet.Spreadsheet")
oSheets.insertByName(sName, oSheet)
End If
oRanges =_
oDocument.createInstance("com.sun.star.sheet.SheetCellRanges")
oRanges.insertByName("", oSheet)
oCells = oRanges.Cells
If oCells.hasElements Then
oCell = oCells.createEnumeration.nextElement
oCursor = oSheet.createCursorByRange(oCell)
oCursor.collapseToCurrentRegion
aAddress = oCursor.RangeAddress
nColumn = aAddress.StartColumn
nRow = aAddress.EndRow
If oSheet.getCellByPosition(nColumn,nRow).Value <> fDate Then
nRow = nRow + 1
End If
Else
oSheet.getCellByPosition(1,18).String = "Date"
oSheet.getCellByPosition(2,18).String = sName
oSheet.getCellRangeByPosition(1,18,2,18).CharWeight = 150
nColumn = 1
nRow = 19
End If
oCell = oSheet.getCellByPosition(nColumn,nRow)
oCell.Value = fDate
oCell.NumberFormat =_
oDocument.NumberFormats.getStandardFormat(_
com.sun.star.util.NumberFormat.DATE, aLanguage )
oSheet.getCellByPosition(nColumn+1,nRow).Value = fValue
End Sub
Subroutine UpdateValue( ) receives the NASDAQ name (sName), the current date
(fDate) and the quote (fValue) as parameters. First, it verifies if a sheet named
sName exists and if not, creates it. The subroutine then creates a cell range for this
sheet. If the program has been run before, this range contains non-emtpy cells, and
118
StarOffice Programmer’s Tutorial ♦ May 2000