| View previous topic :: View next topic |
| Author |
Message |
hosta General User

Joined: 20 Jul 2007 Posts: 24 Location: Grosuplje SLOVENIA
|
Posted: Thu Oct 11, 2007 2:55 pm Post subject: How to insert text from TXT file (from URL) into Calc Cell |
|
|
How can I insert text from TXT file (http://weather.noaa.gov/pub/data/observations/metar/stations/LJCE.TXT) into Open Calc Cell as String.
Thanks.
Hosta |
|
| Back to top |
|
 |
hosta General User

Joined: 20 Jul 2007 Posts: 24 Location: Grosuplje SLOVENIA
|
Posted: Fri Oct 12, 2007 10:36 pm Post subject: Further Info |
|
|
I tried with this code, which I find on www:
| Code: |
Sub GetFTPDocumentTXT()
FTPPath = http://weather.noaa.gov/pub/data/observations/metar/stations/LJCE.TXT"
NewDoc = StarDesktop.loadComponentFromURL(FTPPath, "_blank", 0, Array())
End Sub
|
But there is a problem because txt file opens in new Write document.
Is it possible to copy that text and transfet it to Cell in open Clac document.
Or just transfer text direct to specific cell in open Calc document.
Option _blank, can be changed to _hidden that user cant see open Write doc.
Hosta |
|
| Back to top |
|
 |
hanya Super User

Joined: 04 May 2005 Posts: 543 Location: Japan
|
Posted: Fri Oct 12, 2007 10:48 pm Post subject: |
|
|
Hi Hosta,
you can use csv filter.
| Code: |
Sub GetFTPDocumentTXT()
Dim aArgs(1) As New com.sun.star.beans.PropertyValue
aArgs(0).Name = "FilterName"
aArgs(0).Value = "Text - txt - csv (StarCalc)"
aArgs(1).Name = "FilterOptions"
aArgs(1).Value = ""
FTPPath = "http://weather.noaa.gov/pub/data/observations/metar/stations/LJCE.TXT"
NewDoc = StarDesktop.loadComponentFromURL(FTPPath, "_blank", 0, aArgs)
End Sub
|
Hanya |
|
| Back to top |
|
 |
hosta General User

Joined: 20 Jul 2007 Posts: 24 Location: Grosuplje SLOVENIA
|
Posted: Fri Oct 12, 2007 11:10 pm Post subject: Better solution |
|
|
I finally find better solution (StarOffice7OfficeSuite Basic Programmer's Guide):
| Code: |
Sub getfile
Dim FileNo As Integer
Dim CurrentLine As String
Dim File As String
Dim Msg as String
' Define filename
Filename = "http://weather.noaa.gov/pub/data/observations/metar/stations/LJCE.TXT"
' Establish free file handle
FileNo = Freefile
' Open file (reading mode)
Open Filename For Input As FileNo
' Check whether file end has been reached
Do While not eof(FileNo)
' Read line
Line Input #FileNo, CurrentLine
If CurrentLine <>"" then
Msg = Msg & CurrentLine & Chr(13)
end if
Loop
' Close file
Close #FileNo
Msgbox Msg
End sub
|
Msg can be entered direct to any Cell.
Thanks Hanya. Your code also works fine.
Hosta |
|
| Back to top |
|
 |
|