insert into OPENROWSET('MSDASQL',
'Driver=Microsoft Excel-Treiber (*.xls);
DBQ=C:\temp1.xls',
'
select * from [sheet1$]
')
这是我写的,请各位高手看看那里出错误了!谢谢!另外还请教其他几种写法!求Delphi 中的写法!
'Driver=Microsoft Excel-Treiber (*.xls);
DBQ=C:\temp1.xls',
'
select * from [sheet1$]
')
这是我写的,请各位高手看看那里出错误了!谢谢!另外还请教其他几种写法!求Delphi 中的写法!
var ExcelApp,WorkBook:OLEVariant;
i,j :integer;
xlsFileName:string;
recycle_length:integer;
s_date:string; begin
s_date:=edit2.Text;
savedialog2.Execute;
xlsFileName:=savedialog2.FileName ;
if xlsfilename='' then
begin
showmessage('操作成功取消!');
end
else
begin
if edit2.text=''then
begin with query4 do
begin
CommUtils.initialQuery(Query4,'select count(T_id),sum(T_taxable),sum(T_amountax) from tax');
open;
recycle_length:=query4.Fields[0].AsInteger ; end; progressbar1.Max := recycle_length;
progressbar1.position:=0;
try
ExcelApp:= CreateOleObject( 'Excel.Application' );
WorkBook:=CreateOleobject('Excel.Sheet');
except
application.Messagebox('无法打开Xls文件,请确认已 经安装EXCEL.','',mb_OK+mb_IconStop); Exit;
end;
//workBook:= ExcelApp.workBooks.Open(ExtractFileDir(Application.ExeName)+'excel.xls');
WorkBook:=ExcelApp.workbooks.Add;
ExcelApp.Cells(1,1):='条数';
ExcelApp.Cells(1,2):='工号'; ExcelApp.Cells(1,3):='姓名';
ExcelApp.Cells(1,4):='人民币合计';
ExcelApp.Cells(1,5):='减除费用额'; ExcelApp.Cells(1,6):='应纳税所得税';
ExcelApp.Cells(1,7):='税率';
ExcelApp.Cells(1,8):='速算扣除数';
ExcelApp.Cells(1,9):='扣缴所得税额';
j:=1;
//.
CommUtils.initialTable(table3,TBLNAME_TAX+'.dbf');
//.
table3.Open;
table3.First;
for i:=2 to recycle_length+1 do
begin ExcelApp.Cells(i,1):=j;
ExcelApp.Cells(i,2):=table3.fieldbyname('T_id').Asstring;
ExcelApp.Cells(i,3):=table3.fieldbyname('T_name').Asstring;
ExcelApp.Cells(i,4):=table3.fieldbyname('T_total').Asfloat;
ExcelApp.Cells(i,5):=table3.fieldbyname('T_deduct').Asfloat; ExcelApp.Cells(i,6):=table3.fieldbyname('T_taxable').Asstring;
ExcelApp.Cells(i,7):=FloatToStr(table3.fieldbyname('T_taxrate').asFloat*100)+'%';
ExcelApp.Cells(i,8):=table3.fieldbyname('T_quick').Asfloat;
ExcelApp.Cells(i,9):=table3.fieldbyname('T_amountax').Asfloat; j:=j+1; table3.next;
progressbar1.position:=progressbar1.position+1;
progressbar1.refresh ;
end;
ExcelApp.Cells(recycle_length+2,1):='合计';
ExcelApp.Cells(recycle_length+2,6):=query4.Fields[1].Asfloat;
ExcelApp.Cells(recycle_length+2,9):=query4.Fields[2].Asfloat; WorkBook.SaveAS(xlsFileName); WorkBook.close;
ShowMessage('导入Excel成功!');
end
else
begin
with query4 do
begin
CommUtils.initialQuery(Query4,'select count(T_id),sum(T_taxable),sum(T_amountax) from tax'
+' where T_date = '+ #39+s_date+#39);
open;
recycle_length:=query4.Fields[0].AsInteger ;
end; with query5 do
begin
CommUtils.initialQuery(Query5,'select T_id,T_name,T_total,T_deduct,T_taxrate,T_quick, T_taxable,T_amountax from tax '
+'where T_date ='+ #39+s_date+#39+'order by T_id');
open;
end; progressbar1.Max := recycle_length;
progressbar1.position:=0;
try
ExcelApp:= CreateOleObject( 'Excel.Application' );
WorkBook:=CreateOleobject('Excel.Sheet');
except
application.Messagebox('无法打开Xls文件,请确认已 经安装EXCEL.','',mb_OK+mb_IconStop); Exit;
end;
//workBook:= ExcelApp.workBooks.Open(ExtractFileDir(Application.ExeName)+'excel.xls');
WorkBook:=ExcelApp.workbooks.Add;
ExcelApp.Cells(1,1):='条数';
ExcelApp.Cells(1,2):='工号'; ExcelApp.Cells(1,3):='姓名';
ExcelApp.Cells(1,4):='人民币合计';
ExcelApp.Cells(1,5):='减除费用额'; ExcelApp.Cells(1,6):='应纳税所得税';
ExcelApp.Cells(1,7):='税率';
ExcelApp.Cells(1,8):='速算扣除数';
ExcelApp.Cells(1,9):='扣缴所得税额'; j:=1;
CommUtils.initialTable(table3,TBLNAME_TAX+'.dbf');
table3.Open;
table3.First;
for i:=2 to recycle_length+1 do
begin ExcelApp.Cells(i,1):=j;
ExcelApp.Cells(i,2):=Query5.fieldbyname('T_id').Asstring;
ExcelApp.Cells(i,3):=Query5.fieldbyname('T_name').Asstring;
ExcelApp.Cells(i,4):=Query5.fieldbyname('T_total').Asfloat;
ExcelApp.Cells(i,5):=Query5.fieldbyname('T_deduct').Asfloat; ExcelApp.Cells(i,6):=Query5.fieldbyname('T_taxable').Asstring;
ExcelApp.Cells(i,7):=FloatToStr(Query5.fieldbyname('T_taxrate').asFloat*100)+'%';
ExcelApp.Cells(i,8):=Query5.fieldbyname('T_quick').Asfloat;
ExcelApp.Cells(i,9):=Query5.fieldbyname('T_amountax').Asfloat; j:=j+1; query5.next;
progressbar1.position:=progressbar1.position+1;
progressbar1.refresh ;
end;
ExcelApp.Cells(recycle_length+2,1):='合计';
ExcelApp.Cells(recycle_length+2,6):=query4.Fields[1].Asfloat;
ExcelApp.Cells(recycle_length+2,9):=query4.Fields[2].Asfloat; WorkBook.SaveAS(xlsFileName); WorkBook.close;
ShowMessage('导入Excel成功!'); end; end;end;