uses( ComObj)
procedure TForm1.Button1Click(Sender: TObject); 
 var ExcelApp: Variant;
  begin
   ExcelApp := CreateOleObject( 'Excel.Application' );
   ExcelApp.Visible := false;
   ExcelApp.Caption := '应用程序调用 Microsoft Excel';
   ExcelApp.WorkBooks.Open( 'C:\bb.xls' ); //打开已存在的工作簿
   ExcelApp.Cells[1,4].Value := 'xcvxvcc';
   excelapp.save ;
   if not ExcelApp.ActiveWorkBook.Saved then
   ExcelApp.ActiveSheet.PrintPreview;
   ExcelApp.WorkBooks.Close;
   ExcelApp.Quit;
   application.MessageBox('保存成功','系统提示',0);
  end;
end.有什么方法可以去掉我这里的对话框呢?我真的无法理解,为什么会这样。

解决方案 »

  1.   

    去掉application.MessageBox('保存成功','系统提示',0);?
      

  2.   

    procedure TForm1.Button1Click(Sender: TObject);
     var ExcelApp: Variant;
     Sheet: Variant;
     i,h:integer; j,aa,bb,cc:integer;
     sheetname:string;
    begin
    aa:=strtoint(trim(Edit1.Text));
    bb:=strtoint(trim(edit2.Text));
    cc:=(bb-aa);
    h:=1;
    try
      ExcelApp := CreateOleObject('Excel.Application');
     ExcelApp.Visible := false;
     ExcelApp.Caption := '应用程序调用 Microsoft Excel';
      ExcelApp.WorkBooks.Open( 'C:\222.xls' ); //打开已存在的工作簿
      Except
      ExcelApp.Free;
      exit;
      end;
    while cc>0 do
    begin
    sheetname:='sheet'+inttostr(h);
        Sheet :=ExcelApp.Workbooks[1].WorkSheets[sheetname];
        j:=0;
        while j<7 do
        begin
        for i:=0 to 3  do
        begin
        sheet.cells[j+1, i + 1]:=  '0'+inttostr(aa);
        aa:=aa+1;
        end;
        inc(j);
        end;
       cc:=cc-28;
       h:=h+1;
    end;
     excelapp.Visible := True;
     ShowMessage('ok!');
    end;
      

  3.   

    这是向已存在的222.xls文件写入edit1到edit2的内容,每sheet写28个cell 且,sheet都是已经建好的,因为我需要用到已经存在的表的格式。