一个文件夹有一些excel文件,怎样用程序快速统计这些excel中每个文件的行数,我要的是总行数

解决方案 »

  1.   

    每个Excel相当于一个数据库,使用ADO方式连接这些EXCEL文件,然后进行 SELECT COUNT(*) FROM Sheet名称
      

  2.   

    楼上的,不要说那么简单吧,你这样不如让客户一个一个excel文件打开去看咯,应该不能用连接数据库的方法文件名也是不确定的,这是不是也涉及到遍历的问题。
      

  3.   

    应该要用comobj的方法吧,但怎么遍历
      

  4.   

     随便搜了一个遍历文件的unction MakeFileList(Path,FileExt:string):TStringList ;
    var
    sch:TSearchrec;
    begin
    Result:=TStringlist.Create;
    if rightStr(trim(Path), 1) <> '\' then
    Path := trim(Path) + '\'
    else
    Path := trim(Path);
    if not DirectoryExists(Path) then
    begin
    Result.Clear;
    exit;
    end;
    if FindFirst(Path + '*', faAnyfile, sch) = 0 then
    begin
    repeat
    Application.ProcessMessages;
    if ((sch.Name = '.') or (sch.Name = '..')) then Continue;
    if DirectoryExists(Path+sch.Name) then
    begin
    Result.AddStrings(MakeFileList(Path+sch.Name,FileExt));
    end
    else
    begin
    if (UpperCase(extractfileext(Path+sch.Name)) = UpperCase(FileExt)) or (FileExt='.*') then
    Result.Add(Path+sch.Name);
    end;
    until FindNext(sch) <> 0;
    SysUtils.FindClose(sch);
    end;
    end
      

  5.   

    xlsapp:=createoleobject('excel.application');
    xlsapp.displayalerts:=false;
    xlsapp.screenupdating:=false;
    xlsapp.workbooks.add('c:\the.xls');
    workbook:=xlsapp.workbooks[1];
    sheet:=workbook.worksheets[1];XLsApp.ActiveCell.SpecialCells(xlLastCell).Select;
    maxRows:=XLsApp.ActiveCell.row;      //最大行数
    maxcolumns:=xlsapp.activecell.column;//最大列数要是分页的 话还需要处理下。