一下是我的代码:
    ExcelApplication1:=TExcelApplication.Create(self);
    ExcelWorkbook1:=TExcelWorkbook.Create(self);
    ExcelWorksheet1:=TExcelWorksheet.Create(self);
    Screen.Cursor:=crHourGlass;
    ExcelApplication1.Connect;
    ExcelApplication1.Workbooks.Add(null,0);
    ExcelWorkBook1.ConnectTo(ExcelApplication1.Workbooks[1]);
    ExcelWorkSheet1.ConnectTo(ExcelWorkBook1.Sheets[1] as _WorkSheet);
    ExcelFileName:=OpenDialog1.FileName;
    
    ExcelApplication1.Workbooks.Open(ExcelFileName);
最后一句出错ExcelApplication1.Workbooks.Open(ExcelFileName);,参数不足,但看帮助后边的参数一堆,该写怎么写?

解决方案 »

  1.   

    ExcelApplication1.Workbooks.Open (ExcelFileName,EmptyParam,EmptyParam,EmptyParam,EmptyParam,
    EmptyParam,EmptyParam,EmptyParam,EmptyParam,
        EmptyParam,EmptyParam,EmptyParam,EmptyParam,0)
      

  2.   

    先要 uses ComObj
    var
      i,j: integer;
      iIndex: integer;
      strTemp,strSQL,strForm: string;
      ExcelApp,MyWorkBook :Variant;
    begin
      try
        ExcelApp:=CreateOleObject('Excel.Application');
        MyWorkBook:=CreateOleobject('Excel.Sheet');
      except
        on Exception do raise exception.Create('Can not open *.xls files. Please Confirm Microsoft Excel 2000 has been installed.')
      end;  ExcelApp.Visible := false;
      try
        MyWorkBook:=ExcelApp.workbooks.open('c:\xyz.xls');
      except
        on Exception do raise exception.Create('c:\xyz not found.')
      end;
      MyWorkBook.WorkSheets[1].Activate;
      

  3.   

    楼上的老兄,俺用了那一句,ExcelApplication1.Workbooks.Open (ExcelFileName,EmptyParam,EmptyParam,EmptyParam,EmptyParam,
    EmptyParam,EmptyParam,EmptyParam,EmptyParam,
        EmptyParam,EmptyParam,EmptyParam,EmptyParam,0)
    但结果还是出错啊
    [Error] U_basic2.pas(79): Not enough actual parameters
      

  4.   

    用Excel的三个控件针对Excel操作是有问题的
    以后你会发现。
    最好的办法是用CreateOleObject的方法
    打开Excel
       Try
        V:=CreateOleObject('Excel.Application');
        V.WorkBooks.Open(打开的Excel的路径);
        V.WorkBooks.Add;
        Sheet:=V.WorkBooks[1].WorkSheets[1];
      Except
        ShowMessage('初始化Excel失败,可能没有装Excel或者其他错误,请重起再试');
        V.DisplayAlerts:=False;
        V.Quit;
        Exit;
      end;对Excel单元格子操作
       Sheet.Cells[行,列]:='';关闭Excel
       if not VarIsEmpty(V) then
           begin
              V.DisplayAlerts:=True;
              V.Workbooks[1].Close;
              V.Quit;
              V:=Unassigned;
              Sheet:=Unassigned;
           end;
    对于你的问题打开Excel因该为
    excelapplication1.Workbooks.Open(OpenDialogExcel.FileName,null,null,null,null,null,null,null,null,null,null,null,null,0)
      

  5.   

    使用Delphi对Excel操作的时候存在的问题
    1。做多次导出的时候会有错误,提示你Excel没有安装
    2。在没有退出程序的时候不能查看刚导出的Excel文件
      

  6.   

    不好意思,刚才那段程序我忘记告诉你要定义变量了
    Var
      V,Sheet:variant;
      

  7.   

    http://expert.csdn.net/Expert/topic/1855/1855520.xml?temp=2.248782E-02去看看吧,关于操作excel表的
    excel表和数据库的相互导入导出!~~
      

  8.   

    关于ole的文章多了,搜索一下吧