出
出现派
Unregistered / Unconfirmed
GUEST, unregistred user!
procedure TForm1.exporttoexcel;
var
excelapp1,sheet1:variant;
i:integer;
s:string;
begin
try
excelapp1:=createoleobject('excel.application');
excelapp1.workbooks.add;
sheet1:=excelapp1.workbooks[1].worksheets[1];
with query2 do
begin
close;
sql.Clear;
sql.Add('select * from excel2');
open;
First;
i:=1;
end;
while not query2.Eof do
begin
s:=query2.Fields[0].AsString;
with query1 do
begin
close;
sql.Clear;
sql.Add('select * into excel3 from excel1 where 產品型號='+''''+s+'''');
open;
end;
with query3 do
begin
close;
sql.Clear;
sql.add('select * from excel3');
open;
end;
sheet1.cells[i,1]:=query3.Fields[0].AsString;
sheet1.cells[i,2]:=query3.Fields[2].AsString;
with query3 do
begin
close;
sql.Clear;
sql.add('select sum(結存數量) from excel3');
open;
sheet1.cells[i,3]:=query3.Fields[0].AsFloat;
end;
with query3 do
begin
close;
sql.Clear;
sql.add('drop table excel3');
open;
end;
next;
inc(i);
end;
if not excelapp1.activeworkbook.saved then
excelapp1.activesheet.saveas(editsave.Text);
Messagebox(handle,'導出數據成功!','提示',mb_ok);
excelapp1.quit;
except
Messagebox(handle,'導出數據失敗!','錯誤',mb_ok);
excelapp1.quit;
end;
end;
运行时提示有错,大概是是这样的:Query1:Command Text does not return a result set.
var
excelapp1,sheet1:variant;
i:integer;
s:string;
begin
try
excelapp1:=createoleobject('excel.application');
excelapp1.workbooks.add;
sheet1:=excelapp1.workbooks[1].worksheets[1];
with query2 do
begin
close;
sql.Clear;
sql.Add('select * from excel2');
open;
First;
i:=1;
end;
while not query2.Eof do
begin
s:=query2.Fields[0].AsString;
with query1 do
begin
close;
sql.Clear;
sql.Add('select * into excel3 from excel1 where 產品型號='+''''+s+'''');
open;
end;
with query3 do
begin
close;
sql.Clear;
sql.add('select * from excel3');
open;
end;
sheet1.cells[i,1]:=query3.Fields[0].AsString;
sheet1.cells[i,2]:=query3.Fields[2].AsString;
with query3 do
begin
close;
sql.Clear;
sql.add('select sum(結存數量) from excel3');
open;
sheet1.cells[i,3]:=query3.Fields[0].AsFloat;
end;
with query3 do
begin
close;
sql.Clear;
sql.add('drop table excel3');
open;
end;
next;
inc(i);
end;
if not excelapp1.activeworkbook.saved then
excelapp1.activesheet.saveas(editsave.Text);
Messagebox(handle,'導出數據成功!','提示',mb_ok);
excelapp1.quit;
except
Messagebox(handle,'導出數據失敗!','錯誤',mb_ok);
excelapp1.quit;
end;
end;
代码:
运行时提示有错,大概是是这样的:Query1:Command Text does not return a result set.