OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

How to insert text from TXT file (from URL) into Calc Cell

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API
View previous topic :: View next topic  
Author Message
hosta
General User
General User


Joined: 20 Jul 2007
Posts: 24
Location: Grosuplje SLOVENIA

PostPosted: Thu Oct 11, 2007 2:55 pm    Post subject: How to insert text from TXT file (from URL) into Calc Cell Reply with quote

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
View user's profile Send private message Visit poster's website
hosta
General User
General User


Joined: 20 Jul 2007
Posts: 24
Location: Grosuplje SLOVENIA

PostPosted: Fri Oct 12, 2007 10:36 pm    Post subject: Further Info Reply with quote

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
View user's profile Send private message Visit poster's website
hanya
Super User
Super User


Joined: 04 May 2005
Posts: 543
Location: Japan

PostPosted: Fri Oct 12, 2007 10:48 pm    Post subject: Reply with quote

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
View user's profile Send private message
hosta
General User
General User


Joined: 20 Jul 2007
Posts: 24
Location: Grosuplje SLOVENIA

PostPosted: Fri Oct 12, 2007 11:10 pm    Post subject: Better solution Reply with quote

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
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group