如何判断Excel表格有多少条记录?谢谢!

解决方案 »

  1.   

    用语句 ExcelApp.WorkSheets[1].UsedRange.Rows.Count; 可以取到表的最大行数
      

  2.   

    使用ADO读取,然后对得到的数据机进行操作
      

  3.   

    下面的代码可以解决你的问题:
      ExcelApp.ActiveSheet.Cells.SpecialCells(xlCellTypeLastCell,EmptyParam).Activate;
      lastRow := ExcelApp.ActiveCell.Row;
      lastCol := ExcelApp.ActiveCell.Column;
      

  4.   

    先用ADO连接,然后象普通的表一样操作,记录条数就是recordcount
      

  5.   

    http://www.kaer.cn/default.aspx有ADO连EXCEL的例子,
      

  6.   

    procedure TfrmSG.Button1Click(Sender: TObject);    //uses Excel2000, ComObj
    var
      pc_i:integer;
      xlapp,sheet: variant;
      WBK: OleVariant;
    begin
      xlapp := createoleobject('excel.application');
      if Trim(Edit1.Text)='' then
      begin
        Application.MessageBox('文件名不能为空','警告',MB_OK);
        Exit;
      end;
      WBK := xlapp.workbooks.Open(Edit1.Text);
      sheet := xlapp.workbooks[1].worksheets['sheet1'];
      sheet.Cells.SpecialCells(XlCellTypeLastCell,EmptyParam).Activate;  showmessage(IntToStr(xlapp.ActiveCell.Row));     //行
      showmessage(IntToStr(xlapp.ActiveCell.Column));  //列
      pc_i:=1;
      Edit2.Text := sheet.cells[pc_i,1];     //写入的话用 sheet.cells[pc_i,1] := Edit2.Tex;
      WBK.Close(SaveChanges := True);
      xlapp.Quit;
    end;
      

  7.   

    b_filedCount :=eclApp.ActiveSheet.UsedRange.columns.Count;//返回excel 表中的列数b_row :=eclApp.activesheet.UsedRange.rows.count;        //返回excel 表中的行数