delphi用sql导出excel问题(10)

  • 主题发起人 主题发起人 leizi1128
  • 开始时间 开始时间
L

leizi1128

Unregistered / Unconfirmed
GUEST, unregistred user!
with dm.qry do begin close; sql.Clear; sql.Add('master..xp_cmdshell ''bcp ''SELECT * from msj.dbo.CHQT_Tablecomm'' ''queryout c:/test.xls -c -S''.'' -U''sa'' -P''sa'''); execsql; end;不知道哪里不对,用查询管理器是能用的
 
没人说啊
 
procedure SaveToExecl(DBGrid1: TDBGrid); var s:TStringList; str:string; i:Integer; ASaveDialog : TSaveDialog; tofileName : string; begin str:=''; tofileName := ''; DBGrid1.DataSource.DataSet.DisableControls; try for i:=0 to DBGrid1.DataSource.DataSet.FieldCount-1 do str:=str+DBGrid1.DataSource.DataSet.fields.DisplayLabel+char(9); str:=str+#13; if not DBGrid1.DataSource.DataSet.IsEmpty then begin DBGrid1.DataSource.DataSet.First; while not(DBGrid1.DataSource.DataSet.eof) do begin for i:=0 to DBGrid1.DataSource.DataSet.FieldCount-1 do str:=str+DBGrid1.DataSource.DataSet.Fields.AsString+char(9); str:=str+#13; DBGrid1.DataSource.DataSet.next; end;//end while end; finally DBGrid1.DataSource.DataSet.EnableControls; end; s:=TStringList.Create; try s.Add(str); ASaveDialog := TSaveDialog.Create(nil); try ASaveDialog.Title := '保存文件'; ASaveDialog.Filter := 'Microsof Excel (*.xls)|*.xls'; if ASaveDialog.Execute then begin tofileName := ASaveDialog.FileName; if pos(uppercase('.xls'),uppercase(tofileName)) = 0 then tofileName := tofileName +'.xls'; if Fileexists(tofileName) then begin if MessageDLG('文件已存在,确认覆盖?',mtWarning,[mbOK,mbCancel],0) = mrOk then begin Deletefile(tofileName); s.SaveToFile(tofileName);//保存 Application.MessageBox('数据导出完毕!','信息',MB_OK); end; end else begin s.SaveToFile(tofileName);//保存 Application.MessageBox('数据导出完毕!','信息',MB_OK+MB_ICONINFORMATION); end; end; finally FreeAndNil(ASaveDialog); end; finally FreeAndNil(s); end;
 
后退
顶部