fpspreadsheet: Add basic Excel2003 xml reader.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@7028 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2019-07-13 20:53:15 +00:00
parent eadeeec421
commit b09e7d069b
3 changed files with 357 additions and 4 deletions

View File

@@ -0,0 +1,64 @@
<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
<ProjectOptions>
<Version Value="12"/>
<PathDelim Value="\"/>
<General>
<Flags>
<LRSInOutputDirectory Value="False"/>
<CompatibilityMode Value="True"/>
</Flags>
<SessionStorage Value="InProjectDir"/>
<UseXPManifest Value="True"/>
</General>
<BuildModes Count="1">
<Item1 Name="default" Default="True"/>
</BuildModes>
<PublishOptions>
<Version Value="2"/>
</PublishOptions>
<RunParams>
<FormatVersion Value="2"/>
<Modes Count="1">
<Mode0 Name="default">
<local>
<LaunchingApplication PathPlusParams="\usr\X11R6\bin\xterm -T &apos;Lazarus Run Output&apos; -e $(LazarusDir)\tools\runwait.sh $(TargetCmdLine)"/>
</local>
</Mode0>
</Modes>
</RunParams>
<RequiredPackages Count="1">
<Item1>
<PackageName Value="LazUtils"/>
</Item1>
</RequiredPackages>
<Units Count="1">
<Unit0>
<Filename Value="excelxmlread.lpr"/>
<IsPartOfProject Value="True"/>
</Unit0>
</Units>
</ProjectOptions>
<CompilerOptions>
<Version Value="11"/>
<PathDelim Value="\"/>
<Target>
<Filename Value="excelxmlread"/>
</Target>
<SearchPaths>
<IncludeFiles Value="$(ProjOutDir);..\..\..\source"/>
<OtherUnitFiles Value="..\..\..\source\common"/>
<UnitOutputDirectory Value="..\..\lib\$(TargetCPU)-$(TargetOS)"/>
</SearchPaths>
<Parsing>
<SyntaxOptions>
<UseAnsiStrings Value="False"/>
</SyntaxOptions>
</Parsing>
<Linking>
<Debugging>
<UseExternalDbgSyms Value="True"/>
</Debugging>
</Linking>
</CompilerOptions>
</CONFIG>

View File

@@ -0,0 +1,77 @@
{-------------------------------------------------------------------------------
excelxmlread.lpr
Demonstrates how to read an Excel 2003 xml file using the fpspreadsheet library
-------------------------------------------------------------------------------}
program excelxmlread;
{$mode delphi}{$H+}
uses
Classes, SysUtils, LazUTF8, fpsTypes, fpspreadsheet, xlsxml, fpsutils;
var
workbook: TsWorkbook;
worksheet: TsWorksheet;
inputFilename: string;
dir: string;
i: Integer;
cell: PCell;
{$R *.res}
begin
// Open the input file
dir := ExtractFilePath(ParamStr(0));
inputFileName := dir + 'test.xml';
inputFileName := dir + 'datatypes.xml';
if not FileExists(inputFileName) then begin
WriteLn('Input file ', inputFileName, ' does not exist. Please run excelxmlwrite first.');
Halt;
end;
WriteLn('Opening input file ', inputFilename);
// Create the spreadsheet
workbook := TsWorkbook.Create;
try
workbook.Options := workbook.Options + [boReadFormulas];
workbook.ReadFromFile(inputFilename, sfExcelXML);
WriteLn('The workbook contains ', workbook.GetWorksheetCount, ' sheets.');
WriteLn;
// Write all cells with contents to the console
for i:=0 to workbook.GetWorksheetCount-1 do begin
worksheet := workbook.GetWorksheetByIndex(i);
WriteLn('');
WriteLn('Contents of the worksheet "', worksheet.Name, '":');
WriteLn('');
for cell in worksheet.Cells do
begin
Write(' ',
' Row: ', cell^.Row,
' Col: ', cell^.Col,
' Type: ', cell^.ContentType,
' Value: ', UTF8ToConsole(worksheet.ReadAsText(cell^.Row, cell^.Col))
);
if HasFormula(cell) then
WriteLn(' Formula: ', workSheet.ReadFormulaAsString(cell))
else
WriteLn;
end;
end;
finally
// Finalization
workbook.Free;
end;
{$IFDEF WINDOWS}
WriteLn;
WriteLn('Press ENTER to quit...');
ReadLn;
{$ENDIF}
end.