Files
lazarus-ccr/components/fpspreadsheet/examples/excel2demo/excel2read.lpr
bigchimp 30569b00c0 fpspreadsheet:
- laz_fpspreadsheet packages does not need to be designtime, so do not register it
- cosmetic: example projects are .lpr not .dpr; reflect in comments



git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@3242 8e941d3f-bd1b-0410-a28a-d453659cc2b4
2014-06-26 07:15:51 +00:00

57 lines
1.3 KiB
ObjectPascal

{
excel2read.lpr
Demonstrates how to read an Excel 2.x file using the fpspreadsheet library
AUTHORS: Felipe Monteiro de Carvalho
}
program excel2read;
{$mode delphi}{$H+}
uses
Classes, SysUtils, fpspreadsheet, xlsbiff2, laz_fpspreadsheet;
var
MyWorkbook: TsWorkbook;
MyWorksheet: TsWorksheet;
InputFilename: string;
MyDir: string;
i: Integer;
CurCell: PCell;
begin
// Open the input file
MyDir := ExtractFilePath(ParamStr(0));
InputFileName := MyDir + 'test' + STR_EXCEL_EXTENSION;
if not FileExists(InputFileName) then begin
WriteLn('Input file ', InputFileName, ' does not exist. Please run excel2write first.');
Halt;
end;
WriteLn('Opening input file ', InputFilename);
// Create the spreadsheet
MyWorkbook := TsWorkbook.Create;
MyWorkbook.ReadFromFile(InputFilename, sfExcel2);
MyWorksheet := MyWorkbook.GetFirstWorksheet;
// Write all cells with contents to the console
WriteLn('');
WriteLn('Contents of the first worksheet of the file:');
WriteLn('');
CurCell := MyWorkSheet.GetFirstCell();
for i := 0 to MyWorksheet.GetCellCount - 1 do
begin
WriteLn('Row: ', CurCell^.Row, ' Col: ', CurCell^.Col, ' Value: ',
UTF8ToAnsi(MyWorkSheet.ReadAsUTF8Text(CurCell^.Row, CurCell^.Col))
);
CurCell := MyWorkSheet.GetNextCell();
end;
// Finalization
MyWorkbook.Free;
end.