var
  AppExcel, WrBook, sheet: Variant;  AppExcel.SaveAs('e:\Test.xls');
保存时出错提示为:Method 'SaveAs' not supported by automation object
请教高手我的保存方法那里出错,应该怎麽写?
谢谢!!!

解决方案 »

  1.   

    Variant没有这个方法,我给你个例子好了
    procedure TfrmSG.Button1Click(Sender: TObject);  //uses Excel2000 , ComObj
    var
      pc_i:integer;
      xlapp,sheet: variant;
      WBK: OleVariant;
    begin
      xlapp := createoleobject('excel.application');
      xlapp.visible := True;      //Excel是否可见
      if Trim(Edit1.Text)='' then
      begin
        Application.MessageBox('文件名不能为空','警告',MB_OK);
        Exit;
      end;
      WBK := xlapp.workbooks.Open(Edit1.Text);
      sheet := xlapp.workbooks[1].worksheets['sheet1'];
      sheet.Cells.SpecialCells(XlCellTypeLastCell,EmptyParam).Activate;  //showmessage(IntToStr(xlapp.ActiveCell.Row));
      //showmessage(IntToStr(xlapp.ActiveCell.Column));
      //excelworksheet2.UsedRange[1].Rows.Count));
      //excelworksheet2.UsedRange[1].Columns.Count));
      pc_i:=1;
      Edit2.Text := sheet.cells[pc_i,1];     //写入的话用 sheet.cells[pc_i,1] := Edit2.Tex;
      WBK.Close(SaveChanges := True);  //就是保存
      xlapp.Quit;
    end;