我的OLE在创建的时候就遇到了问题了:代码如下:unit Unit2;interfaceuses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, Buttons, Grids, DBGrids, Db, DBTables,OleServer,Excel97;type
  TForm1 = class(TForm)
    Table1: TTable;
    DataSource1: TDataSource;
    DBGrid1: TDBGrid;
    BitBtn1: TBitBtn;
    procedure BitBtn1Click(Sender: TObject);
  private
    { Private declarations }
    XLApp:Variant;   /////////////////////定义
  public
    { Public declarations }
  end;var
  Form1: TForm1;implementation
   uses ComObj;
{$R *.DFM}procedure TForm1.BitBtn1Click(Sender: TObject);
var
 i,j,k:integer;
 Range1:Variant;
begin
  Table1.Close;
  Table1.Open;
  j:=Table1.RecordCount;
  if j>0 then
  begin
    k:=j+1;
    XLApp.CreateOleObject('Excel.Application');**********************************************************************
Variant does not reference an automation object!    ????????
**********************************************************************    XLApp.visible:=True;
    XLApp.Application.caption:='工作量统计';
    XLApp.Workbooks.add(xlWBatWorkSheet);
    XLApp.Workbooks[1].WorkSheets[1].name:='工作量统计';
    Range1:=XLApp.Workbooks[1].WorkSheets['工作量统计'].Range['A1:C'+inttostr(k)];
    Range1.Borders.LinesStyle:=xlContinuous;
    XLApp.Range('A1'):='N';
    XLApp.Range('B1'):='C';
    for i:=2 to j+1 do
    begin
      XLApp.cells[i,1]:=IntToStr(i-1);
      XLApp.cells[i,2]:=Table1.Fields[0].AsString ;
      XLApp.cells[i,3]:=Table1.Fields[1].AsString ;
      Table1.Next;
    end;
    XLApp.quit;
  end;end;end.
麻烦各位帮看看

解决方案 »

  1.   

    unit Unit2;interfaceuses
      Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
      StdCtrls, Buttons, Grids, DBGrids, Db, DBTables,OleServer,Excel97;type
      TForm1 = class(TForm)
        Table1: TTable;
        DataSource1: TDataSource;
        DBGrid1: TDBGrid;
        BitBtn1: TBitBtn;
        procedure BitBtn1Click(Sender: TObject);
      private
        { Private declarations }
          public
        { Public declarations }
      end;var
      Form1: TForm1;
      XLApp:Variant;implementation
       uses ComObj;
    {$R *.DFM}
    试试!
      

  2.   

    还是不行,一样的错误。EOLEError
      

  3.   

    你是不是先安装的DELPHI,然后再安装的OFFICE,结果DELPHI找不到OFFICE的注册的组件呢?
      

  4.   

    你是不是先安装的DELPHI,然后再安装的OFFICE,结果DELPHI找不到OFFICE的注册的组件呢?
      

  5.   

    如果是先安装的DELPHI,然后再安装的OFFICE的话,重新安装OFFICE。
      

  6.   


    to:WWWWA(aaaa) 
    用控件是可以的!谢谢!
    我确实是  先安装的DELPHI,然后再安装的OFFICE
    那为什么用控件的时候行呢?
    有点怀疑
      

  7.   

    那为什么用控件的时候行呢?
    有点怀疑
    用控件行是因为这个控件是由OFFICE来注册的,而不是由DELPHI注册的
      

  8.   

    是否引用了comobj! 没引用通不过编译的