在程序中用OLE打开Excel文件,如果再用Excel打开另外的一个Excel文件就不行了,Ole是独占的吗?我要用Excel打开另外的一个Excel文件应该怎样做呢,能实现吗?

解决方案 »

  1.   

    这样的话完全可以再单独的打开Excel:unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs,Comobj,Excel2000, StdCtrls;type
      TForm1 = class(TForm)
        Button1: TButton;
        Button2: TButton;
        procedure Button1Click(Sender: TObject);
        procedure Button2Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;
      ExcelApp:Variant;  implementation{$R *.dfm}
    procedure TForm1.Button1Click(Sender: TObject);
    var
      chexingshu:integer;
      Excelx1:string;
      Excelx2:string;
      xl,Cell1: olevariant;
      Sum:integer;
    begin
            ExcelApp := CreateOleObject( 'Excel.Application' );
            ExcelApp.Caption := '昆明理工大学学生素质综合测评表打印';
            ExcelApp.WorkBooks.Add;
            ExcelApp.WorkSheets[1].Activate;
                ExcelApp.Visible := True;
                ExcelApp.ActiveWindow.Zoom := 75;
           chexingshu:=24;
            excelx2:='a1';
            ExcelApp.Cells[1,1].Value :='昆明理工大学学生素质综合测评表';
            ExcelApp.cells.Item[1, 1].font.size := 26;
            ExcelApp.cells.Item[1, 1].RowHeight := 50;
            ExcelApp.cells.Item[1 , 1].Font.Bold := True;
            ExcelApp.cells.Item[1, 1].HorizontalAlignment := xlCenter;
            ExcelApp.cells.Item[1, 1].font.Name := '黑体';
    end;procedure TForm1.Button2Click(Sender: TObject);
    begin
      ExcelApp.ActiveWorkbook.SaveAs('c:\1k1.xls');
    end;end.
      

  2.   

    我是在窗体上嵌入了一个OLE,Excel在窗体上显示,我在另外单独打开一个Excel文件就不可以了
      

  3.   

    而且如果原来有打开的Excel文件,我在运行程序在窗体上激活Ole,我对程序中激活的Excel进行操作,代码如下:    OleContainer1.CreateObject('Excel.Sheet.8',false);
        OleContainer1.DoVerb(ovSHOW);
        xlapp:=OleContainer1.OleObject.Application;
        sheet :=  xlApp.WorkBooks[1].WorkSheets[1];
        Sheet.Cells[1, 1] := '型号';
        Sheet.Cells[1, 2] := '厂家';
        Sheet.Cells[1, 3] := '批号';
        Sheet.Cells[1, 4] := '描述';
        Sheet.Cells[1, 5] := '封装';
        Sheet.Cells[1, 6] := '数量';
        Sheet.Cells[1, 7] := '进价';
        Sheet.Cells[1, 8] := '询价人';
        Sheet.Cells[1, 9] := '询价日期';
        Sheet.Cells[1, 10] := '备注';这些标题就写到我原来打开的Excel文件中去了。不知为何?还请各位大侠告知!
      

  4.   

    我是在窗体上嵌入了一个OLE,Excel在窗体上显示,我在另外单独打开一个Excel文件就不可以了-----------------------------------------------------------------------------------
    晕.......................................
    你说的这个我也能打开啊........
      

  5.   

    procedure TForm1.Button1Click(Sender: TObject);
    var
    Filename:String;
    begin
      opendialog1.filter:='所有文件(*.*)|*.*';
      Opendialog1.InitialDir:=extractfilepath(application.exename);
      if Opendialog1.Execute then
         begin
           FileName:=OpenDialog1.FileName;
           OleContainer1.CreateObjectFromFile(FileName,False);
           OleContainer1.Run;
         end;
    end;你试试这个。可以单独再打开窗体啊.
      

  6.   

    不是的,我是说不可以在程序外面打开Excel文件,
      

  7.   

    你试试我的程序就知道了。
    我在程序里里面已经打开了EXCEL,然后我到程序外面也是可以直接就打开EXCEL的。
      

  8.   

    我要求是程序一运行就打开一个空白的Excel表格,每列的标题为    Sheet.Cells[1, 1] := '型号';
        Sheet.Cells[1, 2] := '厂家';
        Sheet.Cells[1, 3] := '批号';
        Sheet.Cells[1, 4] := '描述';
        Sheet.Cells[1, 5] := '封装';
        Sheet.Cells[1, 6] := '数量';
        Sheet.Cells[1, 7] := '进价';
        Sheet.Cells[1, 8] := '询价人';
        Sheet.Cells[1, 9] := '询价日期';
        Sheet.Cells[1, 10] := '备注';
    ,然后我可以在程序外面也就是可以用Excel另外打开任意多的Excel文件,因为我要把那些另外打开的文件复制到我的窗体上进行编辑等操作,然后存入数据库中。
      

  9.   

    个人感觉delphi操作多个excel时总是不稳定。
      

  10.   

    提示错误
    First chance exception at $7C812AFB. Exception class EOleSysError with message '找不到 %1。'. 
    怎么回事