unit htmlFuncts;
interface
uses MSHTML,
ActiveX, Dialogs, windows, sysutils, stdctrls, forms, classes, comCtrls, commctrl;
function GetDocumentFromFile(
const markup: WideString): IDispatch;
function GetHtmlText(
const markup : widestring; ElementName:
string = '
'; HTMLText : boolean = false):
string;
procedure LadeHTMltoTable(memo : TRichEdit; Liste : TListView);
implementation
procedure LadeHTMltoTable(memo : TRichEdit; Liste : TListView);
var ProcessForm : TForm;
Label1 : TProgressBar;
i,j: Integer;
begin
ProcessForm := Tform.Create(
nil);
ProcessForm.Height := 80;
ProcessForm.Width := 250;
ProcessForm.FormStyle := fsStayOnTop;
ProcessForm.Caption := '
Vortschritt';
Label1 := TProgressBar.Create(ProcessForm);
Label1.Min := 0;
Label1.max := Memo.lines.Count;
Label1.Top := 12;
Label1.Left := 12;
Label1.Width := 220;
Label1.height := 15;
ProcessForm.Position := poMainFormCenter;
ProcessForm.Show;
Label1.Parent := ProcessForm;
label1.show;
j := 0;
for i := 0
to Memo.lines.Count - 1
do
begin
Label1.stepby(1);
ProcessForm.Update;
Label1.refresh;
sleep(5);
end;
ProcessForm.Release;
end;
function GetDocumentFromFile(
const markup: WideString): IDispatch;
var
doc: OleVariant;
f : TextFile;
TextString : Widestring;
begin
AssignFile(f, Markup);
Reset(f);
Result := CoHtmlDocument.Create;
doc := Result;
doc.Open;
while not eof(f)
do
begin
readln(f, textstring);
doc.
write(textstring);
end;
doc.Close;
CloseFile(f);
end;
function GetHtmlText(
const markup: widestring; ElementName:
string = '
'; HTMLText : boolean = false):
string;
var
m_pHtmlDoc2 : IHTMLDocument2;
HTMLElement : IHTMLElement;
HTMLTxtRange : IHTMLTxtRange;
begin
result := '
';
try
m_pHtmlDoc2 := GetDocumentFromFile(Markup)
as IHTMLDocument2;
// document get
if assigned(m_pHtmlDoc2)
then begin
if ElementName = '
'
then
HTMLElement := m_pHtmlDoc2.body
as IHTMLElement
// select body for all text
else
HTMLElement := m_pHtmlDoc2.all.item(ElementName,0)
as IHTMLElement;
if assigned(HTMLElement)
then begin // check
m_pHtmlDoc2.selection.empty;
// clear old selection
HTMLTxtRange := IHTMLTxtRange(m_pHtmlDoc2.selection.createRange);
if assigned(HTMLTxtRange)
then begin
HTMLTxtRange.moveToElementText(HTMLElement);
// move selection to Element
HTMLTxtRange.select;
// select
if HTMLText
then
result := HTMLTxtRange.htmltext
// get the TEXT
else
result := HTMLTxtRange.text;
// get the PLAIN TEXT
m_pHtmlDoc2.selection.empty;
// remove selection
end;
end;
end;
except
on E :
Exception do
ShowMessage(E.ClassName+'
error raised, with message : '+E.
Message);
end;
end;
end.