我想有點一下按鈕,彈出選擇保存路徑對話框,將當前ADOQuery1中的內容保存到EXCEL文件中!
已經使用的代碼
var   i, row, column:integer;
begin
 try  ExcelApplication1.Connect;
  except
    MessageDlg('Excel may not be installed',
      mtError, [mbOk], 0);
    Abort;
  End;
  adoquery1.First;  //從第一條紀錄導出
    ExcelApplication1.Visible[0] := true;
   ExcelApplication1.Caption := 'Excel';
  ExcelApplication1.Workbooks.Add(Null, 0);  //創建excel
  ExcelWorkbook1.ConnectTo(ExcelApplication1.Workbooks[1]);
  ExcelWorksheet1.ConnectTo(ExcelWorkbook1.Worksheets[1] as _Worksheet);
  row:=1;
   for i:=0 to adoquery1.FieldCount-1  do   
   begin
    ExcelWorksheet1.Cells.Item[1,i+1]:=adoquery1.Fields[i].DisplayName;
   end;
   row:=row+1;
    while not adoquery1.Eof do
    begin
     column:=1;
       for i:=1 to adoquery1.FieldCount do    //插入數据
       begin
         ExcelWorksheet1.Cells.Item[row,column]:=adoquery1.Fields[i-1].AsString;
         column:=column+1;
       end;
       adoquery1.Next;
       row:=row+1;
    end;
     ExcelApplication1.Disconnect;  //斷開連接
     ExcelWorkbook1.Disconnect;
     ExcelWorksheet1.Disconnect;
end;

解决方案 »

  1.   

    用SaveDialog1  if SaveDialog1.Execute then
      begin
        SaveDialog1.FileName//即为路径
      end;
      

  2.   

    var
      vpath : oleVariant;vPath := SaveDialog1.FileName;
    ExcelApplication1.save(vPath,...)
      

  3.   

    謝謝樓上的兄弟了我想 彈出保存路徑對話框,保存為EXCEL,保存完后打開文件進行預覽,呵呵有點複雜!
      

  4.   

    就像將一個EXCEL文件另存為時的樣子
      

  5.   

    一样的  if SaveDialog1.Execute then
      begin
        保存excel;
        打开excel文件;(打开SaveDialog1.FileName)
      end;
      

  6.   

    你可以在保存后,不要Disconnect,直接讓它顯示啊
      

  7.   

    直接visible:=true;
    或是再使用API open它