- NEW!
Help answer this question below.
As it turns out all of my "real questions" I have to answer myself. People only want to comment on Jerry Springer situations.
===================================================
'----------
' This function looks up the price of a stock symbol from yahoo.
' Pass in these parameters:
' cStockSymbol - a string, which is the stock symbol.
' Returns:
' A number which is the price of the stock.
'
Function GetStockPrice( ByVal cStockSymbol As String ) As Double
' Use this URL to get a stock symbol from Yahoo.
' For example, this URL...
' http://quote.yahoo.com/d/quotes.csv?s=RHAT&s=MSFT&f=sl1d1t1c1ohgv&e=.csv
' would return a CSV file with the prices for both Red Hat and Microsoft.
' Similarly, we can form a URL for a single stock, based upon the parameter.
cURL = "http://quote.yahoo.com/d/quotes.csv?s=" + cStockSymbol + "&f=sl1d1t1c1ohgv&e=.csv"
' Open up a new spreadsheet from the above URL.
' Specify the CSV filter with options that decode the CSV format comming back from Yahoo.
' Specify the Hidden property so that the spreadsheet does not appear on the screen.
oCalcDoc = StarDesktop.loadComponentFromURL( cURL, "_blank", 0,_
Array( MakePropertyValue( "FilterName", "Text - txt - csv (StarCalc)" ),_
MakePropertyValue( "FilterOptions", "44,34,SYSTEM,1,1/10/2/10/3/10/4/10/5/10/6/10/7/10/8/10/9/10" ),_
MakePropertyValue( "Hidden", True ) ) )
' Get the first sheet of the Calc document.
oSheet = oCalcDoc.getSheets().getByIndex( 0 )
' Get the cell B1, which is the stock price. (Row 0, Col 1.)
nValue = oSheet.getCellByPosition( 1, 0 ).getValue()
' Be sure the close the spreadsheet, because it is hidden, and the user cannot close it.
oCalcDoc.close( True )
' Return the value.
GetStockPrice() = nValue
End Function
'----------
' Create and return a new com.sun.star.beans.PropertyValue.
'
Function MakePropertyValue( Optional cName As String, Optional uValue ) As com.sun.star.beans.PropertyValue
Dim oPropertyValue As New com.sun.star.beans.PropertyValue
If Not IsMissing( cName ) Then
oPropertyValue.Name = cName
EndIf
If Not IsMissing( uValue ) Then
oPropertyValue.Value = uValue
EndIf
MakePropertyValue() = oPropertyValue
End Function
How much money do trades cost at etrade?
by Answerbag Staff on July 2nd, 2010
| 1 person likes this
What is a stock picker?
by Answerbag Staff on June 22nd, 2010
| 1 person likes this
What are reliable OTC Stock Resources?
by Unknown900 on August 27th, 2010
| 1 person likes this
How do I trade stocks on Marsco?
by Answerbag Staff on June 10th, 2010
| 1 person likes this
Why would a good company's stock drop sharply during after hours trading?
by In-Stereo-Type on February 2nd, 2011
| 1 person likes this
You're reading How do I put the updating current price of a stock into an openoffice calc document?
Comments