×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Downloading url using delphi
2

Downloading url using delphi

Downloading url using delphi

(OP)
Is there a way to download a url using delphi as excel file?? i know i can use the TDownLoadURL component but how do i specify that i want in it in an excel file format

RE: Downloading url using delphi

I don't know what version of Delphi you are using, but in Delphi 6 you can do the following:

1) Drop a TRichEdit, a TButton and a TIdHTTP (found in the Indy Clients tab of the Delphi 6 component palette) onto a form.

2) Write a procedure such as the following, where HTTP1 is your TIdHTTP component and reHTML is your TRichEdit:

CODE

procedure TForm1.GetHTMLContent(URL: String);
var
  PostDataStream : TStringStream;
begin
  PostDataStream := TStringStream.Create(');
  try
    HTTP1.Get(URL, PostDataStream);
    reHTML.Text := PostDataStream.DataString;
  finally
    PostDataStream.Free;
  end;
end;

3) Then call your function passing the appropriate URL, for example from a TButton OnClick event:

CODE

procedure TForm1.Button1Click(Sender: TObject);
begin
  GetHTMLContent('http://www.jamstockex.com/LASTQUOT.HTM');
end;

Clive
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"To err is human, but to really foul things up you need a computer."
Paul Ehrlich
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
To get the best answers from this forum see: FAQ102-5096

RE: Downloading url using delphi

I had nothing to do for a moment ago...

CODE

procedure TForm1.Button1Click(Sender: TObject);
var
  MS: TMemoryStream;
  TS: TStrings;
  SaveFrom, SaveTo, i: Integer;
begin
  TS := TStringList.Create;
  MS := TMemoryStream.Create;
  try
    // Get data
    IdHTTP1.Get('http://www.jamstockex.com/LASTQUOT.HTM', MS);
    MS.Position := 0;
    TS.LoadFromStream(MS);

    // Erase all beginning stuff
    SaveFrom := -1;
    SaveTo := -1;

    for i := 0 to TS.Count -1 do
    begin
      if (SaveFrom = -1) and (Pos('ORDINARY SHARES', TS[i]) <> 0) then
        SaveFrom := i+1;

      if (SaveTo = -1) and (Pos('PREFERENCE SHARES', TS[i]) <> 0) then
        SaveTo := i-1;
    end;

    // Check if valid span
    if (SaveFrom = -1) or (SaveTo = -1) then
    begin
      ShowMessage('Error decode page!');
      Exit;
    end;

    // Decode page
    for i := SaveFrom to SaveTo do
    begin
      memo1.lines.add( Copy(TS[i], 17, 27) + Copy(TS[i], 105, 7) );
    end;
  finally
    MS.Free;
    TS.Free;
  end;
end;


//Nordlund

RE: Downloading url using delphi

What I neglected to mention was that my code simply retrieved the HTML source code. After doing this, you need to parse the HTML picking out the relevant data - as Nordlund has shown.

Clive
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"To err is human, but to really foul things up you need a computer."
Paul Ehrlich
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
To get the best answers from this forum see: FAQ102-5096

RE: Downloading url using delphi

You can get a neater look in a TMemo or TRichEdit by setting the font to one that contains fixed-width characters e.g. Courier. Then declare two variables and replace the bottom section of Nordlund's code with the second code segment below:

CODE

var
  security, lastSale: String;

CODE

...
// Decode page
for i := SaveFrom to SaveTo do
begin
  security := Trim(Copy(TS[i], 17, 27));
  lastSale := Trim(Copy(TS[i], 105, 7));
  memo1.lines.add(Format('%-20s %8s', [security, lastSale]));
end;
...

Clive
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"To err is human, but to really foul things up you need a computer."
Paul Ehrlich
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
To get the best answers from this forum see: FAQ102-5096

RE: Downloading url using delphi

(OP)
thanks all for a questions well answered

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close