添加comobj
下面一段代码,供你参与
try
Excel := CreateOLEObject('Excel.Application');
except
Application.MessageBox('Excel没有安装!', '提示信息', 0+64);
Exit;
end;
Excel.Visible := false;
Excel.WorkBooks.Open(xlsFilename);
try
iRow :=2;
iCol := 1;
while trim(Excel.WorkSheets[1].Cells[iRow,iCol].value) <> '' do
begin
with dm.updatestockado do begin
Append;
Fields[1].AsString := trim(Excel.WorkSheets[1].Cells[iRow,iCol].value);
Fields[2].AsFloat := strtofloat(trim(Excel.WorkSheets[1].Cells[iRow,iCol+1].value))*15.12-315;
Fields[3].AsFloat := strtofloat(trim(Excel.WorkSheets[1].Cells[iRow,iCol+2].value))*15.12-315;
Fields[4].Value := trim(Excel.WorkSheets[1].Cells[iRow,iCol+3].value);
Fields[5].Value := trim(Excel.WorkSheets[1].Cells[iRow,iCol+4].value);
Fields[6].Value := now;
iRow := iRow + 1;
end;
end;
Excel.Quit;
dm.updatestockado.UpdateStatus ;
except
Application.MessageBox('导入数据出错!请检查文件的格式是否正确!', '警告', 0+64);
Excel.Quit;
end