导入的代码如下,你可能要稍稍改一下: var Excel,WrkBook,WrkSheet:olevariant; Row, SheetCount, tmp, Col, TotalRow : integer;begin Excel := CreateOleObject('Excel.Application'); WrkBook:=Excel.WorkBooks.Add; Row := 1; SheetCount:=1; Col := 10;//列数 TotalRow := 1000;//行数 for tmp := 0 to Col - 1 do //加入标题: Excel.WorkSheets[SheetCount].Cells[Row,tmp+1].Value:=标题; for Row := 2 to TotalRow+1 do Begin for tmp := 0 to Col - 1 do Excel.WorkSheets[SheetCount].Cells[Row,Tmp+1].Value := 提取出的内容; End; Excel.Activeworkbook.saveas('c:\export.xls'); WrkBook.close; Excel.quit ; Excel:=unassigned ;
将网页load到Tstrings中,在内存中分析每行字符串,到‘<Table ’标记的时候,判断(固定的应该好判断),同样分析表格,写到临时数组或临时数据库中,然后用Delphi中Server页ExcelApplication等部件写到文件中(可参考MSDN)
比如一个表的html代码是<table></table>,一行是<tr></tr>,一个单元格是<td></td>,这是最基本的html代码,只要你能提取出每个单元格的内容,然后通过delphi创建一个CreateOLEObject('Excel.Application')然后导入就可以了
var
Excel,WrkBook,WrkSheet:olevariant;
Row, SheetCount, tmp, Col, TotalRow : integer;begin
Excel := CreateOleObject('Excel.Application');
WrkBook:=Excel.WorkBooks.Add;
Row := 1;
SheetCount:=1;
Col := 10;//列数
TotalRow := 1000;//行数
for tmp := 0 to Col - 1 do //加入标题:
Excel.WorkSheets[SheetCount].Cells[Row,tmp+1].Value:=标题;
for Row := 2 to TotalRow+1 do
Begin
for tmp := 0 to Col - 1 do
Excel.WorkSheets[SheetCount].Cells[Row,Tmp+1].Value := 提取出的内容;
End;
Excel.Activeworkbook.saveas('c:\export.xls');
WrkBook.close;
Excel.quit ;
Excel:=unassigned ;
mail: [email protected]谢谢