2009-08-07 14:16:17 +00:00
|
|
|
{
|
2014-06-26 07:15:51 +00:00
|
|
|
excel8read.lpr
|
2009-08-07 14:16:17 +00:00
|
|
|
|
|
|
|
Demonstrates how to read an Excel 8.x file using the fpspreadsheet library
|
|
|
|
|
|
|
|
AUTHORS: Felipe Monteiro de Carvalho
|
|
|
|
}
|
|
|
|
program excel8read;
|
|
|
|
|
|
|
|
{$mode delphi}{$H+}
|
|
|
|
|
|
|
|
uses
|
|
|
|
Classes, SysUtils, fpspreadsheet, xlsbiff8,
|
2014-08-29 15:02:00 +00:00
|
|
|
fpsutils;
|
2009-08-07 14:16:17 +00:00
|
|
|
|
|
|
|
var
|
|
|
|
MyWorkbook: TsWorkbook;
|
|
|
|
MyWorksheet: TsWorksheet;
|
|
|
|
InputFilename: string;
|
|
|
|
MyDir: string;
|
|
|
|
i: Integer;
|
|
|
|
CurCell: PCell;
|
2009-09-01 16:47:45 +00:00
|
|
|
|
2014-05-14 15:24:02 +00:00
|
|
|
{$R *.res}
|
|
|
|
|
2009-08-07 14:16:17 +00:00
|
|
|
begin
|
|
|
|
// Open the input file
|
|
|
|
MyDir := ExtractFilePath(ParamStr(0));
|
|
|
|
InputFileName := MyDir + 'test.xls';
|
2014-06-18 08:07:00 +00:00
|
|
|
|
|
|
|
if not FileExists(InputFileName) then begin
|
|
|
|
WriteLn('Input file ', InputFileName, ' does not exist. Please run excel8write first.');
|
|
|
|
Halt;
|
|
|
|
end;
|
2009-08-07 14:16:17 +00:00
|
|
|
WriteLn('Opening input file ', InputFilename);
|
|
|
|
|
|
|
|
// Create the spreadsheet
|
|
|
|
MyWorkbook := TsWorkbook.Create;
|
2014-08-29 15:32:43 +00:00
|
|
|
MyWorkbook.Options := MyWorkbook.Options + [boReadFormulas, boAutoCalc];
|
2014-05-23 13:16:01 +00:00
|
|
|
|
2009-08-07 14:16:17 +00:00
|
|
|
MyWorkbook.ReadFromFile(InputFilename, sfExcel8);
|
|
|
|
|
|
|
|
MyWorksheet := MyWorkbook.GetFirstWorksheet;
|
|
|
|
|
|
|
|
// Write all cells with contents to the console
|
|
|
|
WriteLn('');
|
|
|
|
WriteLn('Contents of the first worksheet of the file:');
|
|
|
|
WriteLn('');
|
|
|
|
|
2009-11-08 19:21:23 +00:00
|
|
|
CurCell := MyWorkSheet.GetFirstCell();
|
2009-08-07 14:16:17 +00:00
|
|
|
for i := 0 to MyWorksheet.GetCellCount - 1 do
|
|
|
|
begin
|
2014-05-23 23:13:49 +00:00
|
|
|
Write('Row: ', CurCell^.Row,
|
2009-08-07 14:16:17 +00:00
|
|
|
' Col: ', CurCell^.Col, ' Value: ',
|
|
|
|
UTF8ToAnsi(MyWorkSheet.ReadAsUTF8Text(CurCell^.Row,
|
|
|
|
CurCell^.Col))
|
|
|
|
);
|
2014-05-23 23:13:49 +00:00
|
|
|
if Length(CurCell^.RPNFormulaValue) > 0 then
|
|
|
|
WriteLn(' Formula: ', MyWorkSheet.ReadRPNFormulaAsString(CurCell))
|
|
|
|
else
|
|
|
|
WriteLn;
|
2009-11-08 19:21:23 +00:00
|
|
|
CurCell := MyWorkSheet.GetNextCell();
|
2009-08-07 14:16:17 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
// Finalization
|
|
|
|
MyWorkbook.Free;
|
|
|
|
end.
|
|
|
|
|