You've already forked lazarus-ccr
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@3991 8e941d3f-bd1b-0410-a28a-d453659cc2b4
62 lines
1.3 KiB
ObjectPascal
62 lines
1.3 KiB
ObjectPascal
{
|
|
ooxmlread.lpr
|
|
|
|
Demonstrates how to read an Excel xlsx file using the fpspreadsheet library
|
|
|
|
}
|
|
|
|
program ooxmlread;
|
|
|
|
{$mode delphi}{$H+}
|
|
|
|
uses
|
|
Classes, SysUtils, LazUTF8, fpstypes, fpspreadsheet, xlsxooxml; //fpsallformats;
|
|
|
|
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));
|
|
InputFileName := MyDir + 'a.xlsx';
|
|
if not FileExists(InputFileName) then begin
|
|
WriteLn('Input file ', InputFileName, ' does not exist. Please run opendocwrite first.');
|
|
Halt;
|
|
end;
|
|
WriteLn('Opening input file ', InputFilename);
|
|
|
|
// Create the spreadsheet
|
|
MyWorkbook := TsWorkbook.Create;
|
|
|
|
MyWorkbook.Options := MyWorkbook.Options + [boReadFormulas];
|
|
MyWorkbook.ReadFromFile(InputFilename, sfOOXML);
|
|
|
|
MyWorksheet := MyWorkbook.GetFirstWorksheet;
|
|
|
|
// Write all cells with contents to the console
|
|
WriteLn('');
|
|
WriteLn('Contents of the first worksheet of the file:');
|
|
WriteLn('');
|
|
|
|
for cell in MyWorksheet.Cells do
|
|
WriteLn(
|
|
'Row: ', cell^.Row,
|
|
' Col: ', cell^.Col,
|
|
' Value: ', UTF8ToConsole(MyWorkSheet.ReadAsUTF8Text(cell^.Row, cell^.Col))
|
|
);
|
|
|
|
// Finalization
|
|
MyWorkbook.Free;
|
|
|
|
WriteLn('Finished. Press [ENTER] to close...');
|
|
ReadLn;
|
|
end.
|
|
|