2014-05-25 20:48:49 +00:00
|
|
|
{
|
2014-06-26 07:15:51 +00:00
|
|
|
opendocread.lpr
|
2014-05-25 20:48:49 +00:00
|
|
|
|
|
|
|
Demonstrates how to read an OpenDocument file using the fpspreadsheet library
|
|
|
|
|
2014-06-01 13:08:14 +00:00
|
|
|
AUTHORS: Felipe Monteiro de Carvalho
|
2014-05-25 20:48:49 +00:00
|
|
|
}
|
2014-06-01 13:08:14 +00:00
|
|
|
|
2014-05-25 20:48:49 +00:00
|
|
|
program opendocread;
|
|
|
|
|
|
|
|
{$mode delphi}{$H+}
|
|
|
|
|
|
|
|
uses
|
2015-03-05 10:35:32 +00:00
|
|
|
Classes, SysUtils, LazUTF8, fpstypes, fpspreadsheet, fpsallformats;
|
2014-05-25 20:48:49 +00:00
|
|
|
|
|
|
|
var
|
|
|
|
MyWorkbook: TsWorkbook;
|
|
|
|
MyWorksheet: TsWorksheet;
|
|
|
|
InputFilename: String;
|
|
|
|
MyDir: string;
|
|
|
|
cell: PCell;
|
|
|
|
i: Integer;
|
|
|
|
|
|
|
|
begin
|
|
|
|
MyDir := ExtractFilePath(ParamStr(0));
|
|
|
|
|
|
|
|
// Open the input file
|
|
|
|
MyDir := ExtractFilePath(ParamStr(0));
|
2014-06-01 13:08:14 +00:00
|
|
|
InputFileName := MyDir + 'test.ods';
|
2014-06-18 08:07:00 +00:00
|
|
|
if not FileExists(InputFileName) then begin
|
|
|
|
WriteLn('Input file ', InputFileName, ' does not exist. Please run opendocwrite first.');
|
|
|
|
Halt;
|
|
|
|
end;
|
2014-05-25 20:48:49 +00:00
|
|
|
WriteLn('Opening input file ', InputFilename);
|
|
|
|
|
|
|
|
// Create the spreadsheet
|
|
|
|
MyWorkbook := TsWorkbook.Create;
|
|
|
|
|
|
|
|
MyWorkbook.ReadFromFile(InputFilename, sfOpenDocument);
|
|
|
|
|
|
|
|
MyWorksheet := MyWorkbook.GetFirstWorksheet;
|
|
|
|
|
|
|
|
// Write all cells with contents to the console
|
|
|
|
WriteLn('');
|
|
|
|
WriteLn('Contents of the first worksheet of the file:');
|
|
|
|
WriteLn('');
|
|
|
|
|
2015-03-05 10:35:32 +00:00
|
|
|
for cell in MyWorksheet.Cells do
|
|
|
|
WriteLn(
|
|
|
|
'Row: ', cell^.Row,
|
|
|
|
' Col: ', cell^.Col,
|
2016-03-18 19:50:40 +00:00
|
|
|
' Value: ', UTF8ToConsole(MyWorkSheet.ReadAsText(cell^.Row, cell^.Col))
|
2014-05-25 20:48:49 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
// Finalization
|
|
|
|
MyWorkbook.Free;
|
2016-03-18 19:50:40 +00:00
|
|
|
|
|
|
|
{$IFDEF WINDOWS}
|
|
|
|
WriteLn;
|
|
|
|
Writeln('Press ENTER to quit...');
|
|
|
|
ReadLn;
|
|
|
|
{$ENDIF}
|
2014-05-25 20:48:49 +00:00
|
|
|
end.
|
|
|
|
|