以下是本人一個代碼希望能help your
procedure Tmonth_pc_stock_f.BitBtn4Click(Sender: TObject);
var v,st:variant;
I:integer;
begin
screen.Cursor:=crhourglass;
adostoredproc3.Active:=false;
adostoredproc3.Active:=true;
if adostoredproc3.RecordCount>0 then
begin
v:=createoleobject('excel.application');
v.workbooks.add(getcurrentdir+'/report/min_inventory');
st:=v.workbooks[1].worksheets[1];
st.select;
v.visible:=true;
I:=2;
try
adostoredproc3.DisableControls;
adostoredproc3.First;
while adostoredproc3.eof=false do
begin
st.cells[i,1]:=adostoredproc3ym.AsString;
st.cells[i,2]:=adostoredproc3pos.AsString;
st.cells[i,3]:=adostoredproc3mat_no.AsString;
st.cells[i,4]:=adostoredproc3m_qty.AsString;
st.cells[i,5]:=adostoredproc3mat_nm.AsString;
I:=I+1;
adostoredproc3.next;
end;
adostoredproc3.EnableControls;
Application.Restore;
Application.BringToFront;
screen.Cursor:=crdefault;
MessageDlg(' 資料轉出成功 !', mtInformation, [mbYes], 0);
except
screen.Cursor:=crdefault;
adostoredproc1.EnableControls;
MessageDlg(' 資料沒有轉完而終止', mtWarning, [mbYes], 0);
end;
end
else
MessageDlg('沒有資料!', mtError, [mbYes], 0);
end;