照上面类似的写一个啊,不用我写给你吧

解决方案 »

  1.   

    老大,还是请您帮忙写一个吧,我写的怎么有问题,多谢多谢小天
      

  2.   

    type
    TExcelServer=class(TObject)
      private
        XLApp:Variant;
      public
        constructor Create;{构造函数}
        destructor Destroy;override;{析构函数}
        procedure Open(strFile:string);{打开Excel文件}
        Function GetCellString(R:Integer;C:Integer;Sheet:Variant):String;
        Function GetSheet(BookIndex,SheetPage:Integer):Variant;
        Function GetRows(Sheet: Variant):Integer;
        Function GetCols(Sheet: Variant):Integer;
      end;
    implementation{ TExcelServer }constructor TExcelServer.Create;
    begin
    xlApp := CreateOleObject('Excel.Application');
    end;destructor TExcelServer.Destroy;
    begin
    xlApp.DisplayAlerts:= false;
      xlApp.quit;
    inherited Destroy;
    end;function TExcelServer.GetCellString(R, C: Integer; Sheet: Variant): String;
    begin
    getCellString := Sheet.Cells[R,C];
    end;function TExcelServer.GetCols(Sheet: Variant): Integer;
    begin
    GetCols:=Sheet.Columns;
    end;function TExcelServer.GetRows(Sheet: Variant): Integer;
    begin
    GetRows:=Sheet.ROWS;
    end;function TExcelServer.GetSheet(BookIndex, SheetPage: Integer): Variant;
    begin
    GetSheet:=xlApp.WorkBooks[BookIndex].WorkSheets[SheetPage];
    end;procedure TExcelServer.Open(strFile: string);
    begin
    xlApp.Workbooks.Open(strFile);
    end;end
    之后,取出数据用add.asstring添加即可