Board index » delphi » Reading a csv file?

Reading a csv file?

Thanks for the recommendation, however the link does not appear to be
working
David
Quote
"Mike Shkolnik" <mshkolnik2...@ukr.net> wrote in message

news:anep24$q5i$1@news.lucky.net...
Quote
> David,

> check SMImport suite: http://www.scalabium.com/smi
> There you'll find TSMImportFromText component which allow to load CSV-file
> into dataset (a lot of import modes)

> --
> With best regards, Mike Shkolnik
> EMail: mshkol...@scalabium.com
> http://www.scalabium.com

> "news" <mou...@hotmail.com> ???Y/???Y ????? ???Y??:
> news:3d9a5953$0$22173$afc38c87@news.optusnet.com.au...
> > Hi All
> > Anyone have a simple procedure to readin or loadfromfile a csv file into
a
> > stringgrid or dbgrid?
> > I want to iterate through a series of daily log files for a webserver
and
> > run reports by sites visited by users.

> > the file structure is like this

> > computername, date, time, url,

> > in the file structure sometime the field is null and the column
decriptor
> is
> > missing and there is no comma. In other words the file structure is not
> > consistent.

> > I prefer not to have to buy a customised grid for such a small job.

> > Thanks in advance
> > David

 

Re:Reading a csv file?


Quote
> > > Anyone have a simple procedure to readin or loadfromfile a csv file
into
> a
> > > stringgrid or dbgrid?

Picked this up on one of the use groups:

{  This procedure loads a CSV file into a TStringGrid.
   Author: Gary Williams}
procedure LoadStringGridFromCSVFile(const StringGrid: TStringGrid;
                                    const FileName: String);
var
  I: Cardinal;
  CSV: TStrings;
begin
  CSV := TStringList.Create;
  try
    CSV.LoadFromFile(FileName);
    StringGrid.RowCount := CSV.Count;

    for I := 1 to CSV.Count do
    begin
      StringGrid.Rows[I-1].CommaText := CSV[I-1];
    end;
  finally
    CSV.Free;
  end;
end; ///////////////////////////////////////////////////////////

{ This procedure saves a TStringGrid into a CSV file.
  Author: Gary Williams}
procedure SaveStringGridToCSVFile(const StringGrid: TStringGrid;
                                  const FileName: String);
var
  I: Integer;
  CSV: TStrings;
begin
  CSV := TStringList.Create;
  try
    for I := 1 to StringGrid.RowCount do
    begin
      CSV.Add(StringGrid.Rows[I-1].CommaText);
    end;
    CSV.SaveToFile(FileName);
  finally
    CSV.Free;
  end;
end; ///////////////////////////////////////////////////////////

Re:Reading a csv file?


Thanks a million
That looks like it will work.
I will give it a go.
David
Quote
"Arvin" <nota...@{*word*104}trails.com> wrote in message

news:AI4n9.456529$5r1.19142478@bin5.nnrp.aus1.giganews.com...
Quote
> > > > Anyone have a simple procedure to readin or loadfromfile a csv file
> into
> > a
> > > > stringgrid or dbgrid?

> Picked this up on one of the use groups:

> {  This procedure loads a CSV file into a TStringGrid.
>    Author: Gary Williams}
> procedure LoadStringGridFromCSVFile(const StringGrid: TStringGrid;
>                                     const FileName: String);
> var
>   I: Cardinal;
>   CSV: TStrings;
> begin
>   CSV := TStringList.Create;
>   try
>     CSV.LoadFromFile(FileName);
>     StringGrid.RowCount := CSV.Count;

>     for I := 1 to CSV.Count do
>     begin
>       StringGrid.Rows[I-1].CommaText := CSV[I-1];
>     end;
>   finally
>     CSV.Free;
>   end;
> end; ///////////////////////////////////////////////////////////

> { This procedure saves a TStringGrid into a CSV file.
>   Author: Gary Williams}
> procedure SaveStringGridToCSVFile(const StringGrid: TStringGrid;
>                                   const FileName: String);
> var
>   I: Integer;
>   CSV: TStrings;
> begin
>   CSV := TStringList.Create;
>   try
>     for I := 1 to StringGrid.RowCount do
>     begin
>       CSV.Add(StringGrid.Rows[I-1].CommaText);
>     end;
>     CSV.SaveToFile(FileName);
>   finally
>     CSV.Free;
>   end;
> end; ///////////////////////////////////////////////////////////

Other Threads