home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / pascal / library / dos / lotus / lotuswks / symto123.pas next >
Encoding:
Pascal/Delphi Source File  |  1986-05-30  |  4.9 KB  |  134 lines

  1. {$V-,K-}  { Speed up the program}
  2.  
  3. {
  4.    This Program converts a Symphony worksheet into a 1-2-3 worksheet.
  5.    Since portions of Symphony worksheets are incompatible with 1-2-3,
  6.    those parts are ommitted.
  7.  
  8.    A Symphony worksheet shares a number of record types with 1-2-3.
  9.    These record types are duplicated.  The Symphony record types which
  10.    have no corresponding match in 1-2-3 are ignored, with the exception
  11.    of record type 71.  A 71 is the Symphony range name.  Since it is
  12.    reasonably important to have those in the 1-2-3 worksheet.  The
  13.    Symphony record type 71 is converted to a 1-2-3 type 11.
  14.  
  15.    There is one type of record problem that cannot be detected and
  16.    corrected.  A Symphony formula can contain a construct like:
  17.    @IF(+C23=0,"",+C23*1.1)
  18.    Since a 1-2-3 formula cannot return a string, this will cause 1-2-3
  19.    to lock up when loading the worksheet.  Pure string formulas are not
  20.    affected since they use a different record type.
  21.  
  22.                                                                           }
  23.  
  24. Program SymTo123;
  25.  
  26. Var RecType,RecLen             : Integer;
  27.     FileLength                 : Real;            { has to be real for }
  28.     Fpoint                     : Real;            { handling large files  }
  29.     SFile                      : File of Byte;    { We need to read the file }
  30.     LFile                      : File of Byte;    { a byte at a time         }
  31.     SfileName                  : String[14];
  32.     LFileName                  : String[14];
  33.     Byte1,Byte2                : Byte;
  34.     I,Pct                      : Integer;
  35.     SCount,LCount              : Integer;
  36.  
  37.  
  38. {   Declarations done, get the two filenames from the user and open the
  39.     files.  We assume the user knows what he's doing so we don't worry
  40.     about overwriting any existing files.  If there is an I/O problem
  41.     let the program crash.
  42.                                                                           }
  43.  
  44. Begin
  45.      ClrScr;
  46.      Write('Enter the FULL name of the Symphony worksheet: ');
  47.      Read(SFileName);
  48.      Writeln;
  49.      Write('Enter the FULL name of the new 1-2-3 worksheet: ');
  50.      Read(LFileName);
  51.      For I := 1 to 14 Do Begin
  52.          SFileName[I] := UpCase(SFileName[I]);
  53.          LFileName[I] := UpCase(LFileName[I]);
  54.      End;
  55.      ClrScr;
  56.      Assign(Sfile,SfileName);
  57.      Assign(LFile,LFileName);
  58.      Reset(Sfile);
  59.      Rewrite(LFile);
  60.  
  61.  
  62.  
  63.      { The files are open.  Display the length of the file and setup a
  64.        display of the % of the file processed so the user doesn't get
  65.        impatient.                                                         }
  66.  
  67.  
  68.      FileLength := LongFileSize(Sfile);
  69.      Writeln('The size of: ',SFileName,'  is: ',FileLength:8:0);
  70.      Fpoint := 0.0;
  71.      SCount := 0;
  72.      LCount := 0;
  73.      GoToXY(9,5);
  74.      Write(' of the file has been processed.');
  75.  
  76.  
  77. {    Processing from the beginning to the end of the file, read each
  78.      record and the length (the 1st two words); determine what to do.
  79.      If it's a Symphony only record, skip to the beginning of the next
  80.      record.  If it's a 1-2-3 record, write the header out then write
  81.      the rest of the record.  If it's a beginning of file record, change
  82.      the ID field to show it's really a 1-2-3 worksheet.  Finally, if it's
  83.      a type 71 record, change it to a type 11 record.                     }
  84.  
  85.      While Fpoint<FileLength Do
  86.      Begin
  87.           GoToXY(5,5);
  88.           Pct := Round(Fpoint/FileLength*100);
  89.           Write(Pct,'%');
  90.           Read(SFile,Byte1);
  91.           Read(SFile,Byte2);
  92.           RecType := Swap(Byte2) + Byte1;
  93.           Read(Sfile,Byte1);
  94.           Read(Sfile,Byte2);
  95.           RecLen := Swap(Byte2) + Byte1;
  96.           Fpoint := Fpoint + 4.0;
  97.           SCount := SCount + 1;
  98.           If RecType=71 Then RecType := 11;
  99.           If RecType<50  Then
  100.           Begin
  101.                LCount := Lcount + 1;
  102.                Byte1 := RecType;
  103.                Byte2 := Swap(RecType);
  104.                Write(LFile,Byte1);
  105.                Write(LFile,Byte2);
  106.                Byte1 := RecLen;
  107.                Byte2 := Swap(RecLen);
  108.                Write(LFile,Byte1);
  109.                Write(LFile,Byte2);
  110.                For I := 1 to RecLen Do
  111.                Begin
  112.                     Read(Sfile,Byte1);
  113.                     If (RecType=0) and (I=1) Then Byte1 := Byte1 - 1;
  114.                     Write(Lfile,Byte1);
  115.                End;
  116.           End
  117.           Else LongSeek(Sfile,Fpoint+RecLen);
  118.           Fpoint := Fpoint + RecLen;
  119.      End;
  120.  
  121.  
  122. {    That's the entire file, close up everything and tell the people
  123.      all about it.                                                        }
  124.  
  125.      Close(SFile);
  126.      Close(Lfile);
  127.      ClrScr;
  128.      Writeln;
  129.      Writeln(SCount:5,' records read from Symphony worksheet: ',SFileName);
  130.      Writeln;
  131.      Writeln(LCount:5,' records written to 1-2-3 worksheet: ',LFileName);
  132.      Writeln;
  133. End.
  134.