先把表格里的内容取出来放在数组里,再将数组里的数据存入Excel中。
从表格中取数据的方法:
uses mshtml;
function GetHtmlTableCell(aTable:IHTMLTable;aRow,aCol:integer):IHTMLElement;
var
Row:IHTMLTableRow;
node:IHTMLElement;
begin
Row:=aTable.rows.item(aRow,aRow) as IHTMLTableRow;
Result:=Row.cells.item(aCol,aCol) as IHTMLElement;
end;
function GetHtmlTable(aDoc:IHTMLDocument2;aIndex:Integer):IHTMLTable;
var
list:IHTMLElementCollection;
begin
list:=aDoc.all.tags('table') as IHTMLElementCollection;
Result:=list.item(aIndex,aIndex) as IHTMLTable;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
Docintf:IHTMLDocument2;
tblintf:IHTMLTable;
begin
docintf:=WebBrowser1.Document as IHTMLDocument2;
tblintf:=GetHtmlTable(docintf,0);
ShowMessage( GetHtmlTableCell(tblintf,1,1).innerText);
end;