You've already forked lazarus-ccr
fpspreadsheet: Initial support for reading html files (data only, no formats, no nested tables).
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@4236 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@ -23,7 +23,7 @@ begin
|
||||
MyDir := ExtractFilePath(ParamStr(0));
|
||||
InputFileName := MyDir + 'test' + STR_COMMA_SEPARATED_EXTENSION;
|
||||
if not FileExists(InputFileName) then begin
|
||||
WriteLn('Input file ', InputFileName, ' does not exist. Please run excel2write first.');
|
||||
WriteLn('Input file ', InputFileName, ' does not exist. Please run csvwrite first.');
|
||||
Halt;
|
||||
end;
|
||||
|
||||
|
@ -0,0 +1,66 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<CONFIG>
|
||||
<ProjectOptions>
|
||||
<Version Value="9"/>
|
||||
<PathDelim Value="\"/>
|
||||
<General>
|
||||
<Flags>
|
||||
<LRSInOutputDirectory Value="False"/>
|
||||
</Flags>
|
||||
<SessionStorage Value="InProjectDir"/>
|
||||
<MainUnit Value="0"/>
|
||||
<Title Value="htmlread"/>
|
||||
<UseAppBundle Value="False"/>
|
||||
</General>
|
||||
<VersionInfo>
|
||||
<StringTable ProductVersion=""/>
|
||||
</VersionInfo>
|
||||
<BuildModes Count="1">
|
||||
<Item1 Name="default" Default="True"/>
|
||||
</BuildModes>
|
||||
<PublishOptions>
|
||||
<Version Value="2"/>
|
||||
<IgnoreBinaries Value="False"/>
|
||||
<IncludeFileFilter Value="*.(pas|pp|inc|lfm|lpr|lrs|lpi|lpk|sh|xml)"/>
|
||||
<ExcludeFileFilter Value="*.(bak|ppu|ppw|o|so);*~;backup"/>
|
||||
</PublishOptions>
|
||||
<RunParams>
|
||||
<local>
|
||||
<FormatVersion Value="1"/>
|
||||
<LaunchingApplication PathPlusParams="\usr\X11R6\bin\xterm -T 'Lazarus Run Output' -e $(LazarusDir)\tools\runwait.sh $(TargetCmdLine)"/>
|
||||
</local>
|
||||
</RunParams>
|
||||
<RequiredPackages Count="1">
|
||||
<Item1>
|
||||
<PackageName Value="LazUtils"/>
|
||||
</Item1>
|
||||
</RequiredPackages>
|
||||
<Units Count="1">
|
||||
<Unit0>
|
||||
<Filename Value="htmlread.lpr"/>
|
||||
<IsPartOfProject Value="True"/>
|
||||
</Unit0>
|
||||
</Units>
|
||||
</ProjectOptions>
|
||||
<CompilerOptions>
|
||||
<Version Value="11"/>
|
||||
<PathDelim Value="\"/>
|
||||
<Target>
|
||||
<Filename Value="htmlread"/>
|
||||
</Target>
|
||||
<SearchPaths>
|
||||
<OtherUnitFiles Value="..\..\.."/>
|
||||
<UnitOutputDirectory Value="..\..\lib\$(TargetCPU)-$(TargetOS)"/>
|
||||
</SearchPaths>
|
||||
<Parsing>
|
||||
<SyntaxOptions>
|
||||
<UseAnsiStrings Value="False"/>
|
||||
</SyntaxOptions>
|
||||
</Parsing>
|
||||
<Linking>
|
||||
<Debugging>
|
||||
<DebugInfoType Value="dsDwarf2Set"/>
|
||||
</Debugging>
|
||||
</Linking>
|
||||
</CompilerOptions>
|
||||
</CONFIG>
|
@ -0,0 +1,70 @@
|
||||
{
|
||||
htmlread.dpr
|
||||
|
||||
Demonstrates how to read a html file using the fpspreadsheet library.
|
||||
IMPORTANT: Requires the output file of the htmlwrite demo.
|
||||
}
|
||||
|
||||
program htmlread;
|
||||
|
||||
{$mode delphi}{$H+}
|
||||
|
||||
uses
|
||||
Classes, SysUtils, LazUTF8, fpstypes, fpsutils, fpspreadsheet, fpshtml;
|
||||
|
||||
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_HTML_EXTENSION;
|
||||
if not FileExists(InputFileName) then begin
|
||||
WriteLn('Input file ', InputFileName, ' does not exist. Please run htmlwrite first.');
|
||||
Halt;
|
||||
end;
|
||||
|
||||
WriteLn('Opening input file ', InputFilename);
|
||||
|
||||
// Parameters
|
||||
HTMLParams.TableIndex := 0;
|
||||
|
||||
// Create the spreadsheet
|
||||
MyWorkbook := TsWorkbook.Create;
|
||||
try
|
||||
MyWorkbook.Options := MyWorkbook.Options + [boReadFormulas];
|
||||
MyWorkbook.ReadFromFile(InputFilename, sfHTML);
|
||||
|
||||
MyWorksheet := MyWorkbook.GetFirstWorksheet;
|
||||
|
||||
// Write all cells with contents to the console
|
||||
WriteLn('');
|
||||
WriteLn('Contents of the first worksheet of the file:');
|
||||
WriteLn('');
|
||||
|
||||
for CurCell in MyWorksheet.Cells do
|
||||
begin
|
||||
WriteLn(
|
||||
'Row: ', CurCell^.Row,
|
||||
' Col: ', CurCell^.Col,
|
||||
' Value: ', UTF8ToConsole(MyWorkSheet.ReadAsUTF8Text(CurCell^.Row, CurCell^.Col))
|
||||
);
|
||||
end;
|
||||
|
||||
finally
|
||||
// Finalization
|
||||
MyWorkbook.Free;
|
||||
end;
|
||||
|
||||
{$IFDEF MSWINDOWS}
|
||||
WriteLn;
|
||||
WriteLn('Press ENTER to exit.');
|
||||
ReadLn;
|
||||
{$ENDIF}
|
||||
end.
|
||||
|
@ -1 +1,3 @@
|
||||
This demo demonstrates how to use fpspreadsheet to read and write html files which can be opened by the browser.
|
||||
|
||||
Please run the write demo before the read demo in order to create the required spreadsheet file.
|
||||
|
Reference in New Issue
Block a user