HELP : Reading EXCEL file by Turbo Pascal 
Author Message
 HELP : Reading EXCEL file by Turbo Pascal

Hi,

I am writing a program which needs to read the data sheet created by
EXCEL in the text format. I want my program to be able to read the
EXCEL file and put the related data for each cell in the approperiate
variable in my Turbo Pascal program. Also I need to do the reverse and
create the data by the Turbo Pascal program and read the data into an
EXCEL sheet. I should mention that the data is a mixture of characters
(string) and numbers.

Any ideas ?

Thanks in advance for your help.

Regards

M. Abdollahi  



Wed, 18 Jun 1902 08:00:00 GMT  
 HELP : Reading EXCEL file by Turbo Pascal

Quote:

>Hi,
>I am writing a program which needs to read the data sheet created by
>EXCEL in the text format. I want my program to be able to read the
>EXCEL file and put the related data for each cell in the approperiate
>variable in my Turbo Pascal program. Also I need to do the reverse and
>create the data by the Turbo Pascal program and read the data into an
>EXCEL sheet. I should mention that the data is a mixture of characters
>(string) and numbers.

Anything is stored as a String in text formats. There are two different
text format supported by Excel:

1. Fixed field length. Here every field is filled up with blanks like this:
     field1            field2           field3
     something         anything         again something
     maybe a number    1234             hello world

   To read this you can define a record:
     type
       TDataRecord = record
         Field1: Array[1..10] of Char;
         Field2: Array[1..15] of Char;
         Field3: Array[1.. 8] of Char;
       end;
       FDataRecord: File of TDataRecord;

    and access like this:
       var
         d: TDataRecord;
         f: FDataRecord;
       begin
         Assign(f, fName);
         Reset(f),
         while not Eof(f) do begin
           Read(f, d);
           Writeln(d.Field1, d.Field2, d.Field3);
         end
         Close(f);
       end;

2. Fields delimited by a special charactore, most often ';' is used:
     Field1;Field2;Field3
     Bla;Bla;Bla;
   and so on. But still each line contains exactly one record.
   Here you have to parse the input:
     var
       f: Text;
       s: String;
     begin
       Assign(f, fName);
       Reset(f);
       while not Eof(f) do begin
         Readln(f, s);
         Field1 := Copy(s, 1, Pos(';',s)-1);
         s := Copy(s, Pos(';',s)+1, 255);
         Field2 := Copy(s, 1, Pos(';',s)-1);
         ..and so on..
       end;
       Close(f);
     end;

By the way:
  The format of Excel Workbooks is documented in the 'Excel Developper Kit'.
  About 90% of that book is about the file format which is rather complicated,
  the rest is about capi, clipboard format, OLE-basics. It is not worth buying
  it.

All the best,
  Robert Beicht  

  http://www.lrz-muenchen.de/~p7003ot



Wed, 18 Jun 1902 08:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Can Excel read a Pascal binary file?

2. Help : Anyone know how to read/write from/into Excel files

3. reading excel files

4. How to read a EXCEL.XLS file ?

5. Reading Excel 97 files with D2

6. Reading Excel files

7. Read Excel files?

8. Read Excel files?

9. Reading Excel Files thru ODBC

10. Reading Excel files in BPW

11. Reading different size variables from same open file in Turbo Pascal 3.0

12. I NEED TURBO PASCAL 7.0 HELP FILE (TURBO.TPH)

 

 
Powered by phpBB® Forum Software