You've already forked lazarus-ccr
NOTE: This revision breaks existing code if the worksheet's DefaultRowHeight/DefaultColWidth is changed - value must be in millimeters now. Methods for accessing individual row heiths and column widths are fine, but are marked as deprecated, they use the old units. Optionally a unit parameter can be specified. git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@4568 8e941d3f-bd1b-0410-a28a-d453659cc2b4
79 lines
1.7 KiB
ObjectPascal
79 lines
1.7 KiB
ObjectPascal
{
|
|
htmlread_http.dpr
|
|
|
|
Demonstrates how to read a html file from the internet using the fpspreadsheet library.
|
|
}
|
|
|
|
program htmlread_http;
|
|
|
|
{$mode delphi}{$H+}
|
|
|
|
uses
|
|
Classes, SysUtils, LazUTF8, fphttpclient, fpstypes, fpsutils, fpspreadsheet, fpshtml;
|
|
|
|
var
|
|
MyWorkbook: TsWorkbook;
|
|
MyWorksheet: TsWorksheet;
|
|
i: Integer;
|
|
CurCell: PCell;
|
|
stream: TMemoryStream;
|
|
|
|
const
|
|
// url = 'http://unicode.e-workers.de/entities.php';
|
|
url = 'http://www.freepascal.org/docs.var';
|
|
|
|
begin
|
|
stream := TMemoryStream.Create;
|
|
try
|
|
// Get file from the internet
|
|
with TFPHttpClient.Create(nil) do
|
|
try
|
|
Get(url, stream);
|
|
finally
|
|
Free;
|
|
end;
|
|
|
|
// Parameters
|
|
HTMLParams.TableIndex := 0;
|
|
|
|
// Create the spreadsheet
|
|
MyWorkbook := TsWorkbook.Create;
|
|
try
|
|
MyWorkbook.Options := MyWorkbook.Options + [boReadFormulas];
|
|
MyWorkbook.ReadFromStream(stream, 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
|
|
Write(
|
|
'Row: ', CurCell^.Row,
|
|
' Col: ', CurCell^.Col,
|
|
' Value: ', UTF8ToConsole(MyWorkSheet.ReadAsText(CurCell^.Row, CurCell^.Col))
|
|
);
|
|
if MyWorksheet.HasHyperlink(CurCell) then
|
|
Write(' Hyperlink: ', MyWorksheet.ReadHyperlink(CurCell).Target);
|
|
WriteLn;
|
|
end;
|
|
|
|
finally
|
|
// Finalization
|
|
MyWorkbook.Free;
|
|
end;
|
|
finally
|
|
stream.Free;
|
|
end;
|
|
|
|
{$IFDEF WINDOWS}
|
|
WriteLn;
|
|
WriteLn('Press ENTER to quit...');
|
|
ReadLn;
|
|
{$ENDIF}
|
|
end.
|
|
|