procedure TForm5.BitBtn1Click(Sender: TObject);
var
excelapp,myworkbook:variant;
i:integer;
begin
screen.Cursor:=crhourglass;
g1.Visible :=true;
g1.MaxValue :=table1.RecordCount ;
try
ExcelApp:=CreateOleObject('Excel.Application');
label1.Caption:='正在导入数据...';
MyWorkBook:=CreateOleobject('Excel.Sheet');
except
application.Messagebox('无法打开Xls文件,请确认已 经安装EXCEL.',
'',mb_OK+mb_IconStop);
Exit;
end;
MyworkBook:=ExcelApp.workBooks.Add;
MyWorkBook.WorkSheets[1].cells[1,1].value:='车号' ;
MyWorkBook.WorkSheets[1].cells[1,2].value:='驾驶员';
MyWorkBook.WorkSheets[1].cells[1,3].value:='客户单位';
MyWorkBook.WorkSheets[1].cells[1,4].value:='起讫点';
MyWorkBook.WorkSheets[1].cells[1,5].value:='日期';
MyWorkBook.WorkSheets[1].cells[1,6].value:='贷物';
MyWorkBook.WorkSheets[1].cells[1,7].value:='数量';
MyWorkBook.WorkSheets[1].cells[1,8].value:='单位';
MyWorkBook.WorkSheets[1].cells[1,9].value:='单价';
MyWorkBook.WorkSheets[1].cells[1,10].value:='行程';
MyWorkBook.WorkSheets[1].cells[1,11].value:='运输费';
MyWorkBook.WorkSheets[1].cells[1,12].value:='过路费';
MyWorkBook.WorkSheets[1].cells[1,13].value:='实绩';
MyWorkBook.WorkSheets[1].cells[1,14].value:='经办人';
i:=2;
with table1 do begin
DisableControls ;
first;
while not eof do begin
g1.Progress :=RecNo;
MyWorkBook.WorkSheets[1].cells[i,1].value:=fieldbyname('num').asstring;
MyWorkBook.WorkSheets[1].cells[i,2].value:=fieldbyname('dname').asstring;
MyWorkBook.WorkSheets[1].cells[i,3].value:=fieldbyname('cust').asstring;
MyWorkBook.WorkSheets[1].cells[i,4].value:=fieldbyname('daddr').asstring;
MyWorkBook.WorkSheets[1].cells[i,5].value:=fieldbyname('date1').asstring;
MyWorkBook.WorkSheets[1].cells[i,6].value:=fieldbyname('hwu').asstring;
MyWorkBook.WorkSheets[1].cells[i,7].value:=fieldbyname('sliang').asstring;
MyWorkBook.WorkSheets[1].cells[i,8].value:=fieldbyname('danwei').asstring;
MyWorkBook.WorkSheets[1].cells[i,9].value:=fieldbyname('djia').asstring;
MyWorkBook.WorkSheets[1].cells[i,10].value:=fieldbyname('xingch').asstring;
MyWorkBook.WorkSheets[1].cells[i,11].value:=fieldbyname('ysfei').asstring;
MyWorkBook.WorkSheets[1].cells[i,12].value:=fieldbyname('glfei').asstring;
MyWorkBook.WorkSheets[1].cells[i,13].value:=fieldbyname('score').asstring;
MyWorkBook.WorkSheets[1].cells[i,14].value:=fieldbyname('getman').asstring;
i:=i+1;
next;
end;
//在此处插入读数据库及写Excel文档的代码
end;
screen.Cursor:=crdefault;
table1.EnableControls ;
g1.Visible:=false;
label1.Caption :='';
excelapp.visible:=true;
end;
g1 为 progressbar