读取一个EXCEL文件页面,
可能页面有若干行数据,用什么方法可以知道此页面的行数呢?
我用AExcelBook.Worksheets[i].Rows.count这个方法得到的是页面的最大行数,而不是实际的数据行

解决方案 »

  1.   

    procedure TForm1.Button1Click(Sender: TObject);
       var i,k:integer;
       ExcelID: Variant;
       code,ifsix:string;
    begin
       if opendialog1.Execute then begin
          ExcelID:=CreateOleObject('Excel.Application');
          ExcelID.workbooks.open(opendialog1.FileName);
          ExcelID.WorkSheets[1].Activate;
          i:=ExcelID.worksheets[1].UsedRange.Rows.Count;
          for k:=1 to i-1 do begin
          code:= copy(ExcelID.Cells[k+1,1].Value,1,6);
          ifsix:=copy(ExcelID.Cells[k+1,1].Value,1,1);
              with adoquery2 do
              begin
                close;
                sql.Clear;
                sql.Add('select * from diannei where ProductBarcode='+code+'') ;
                open;
              end;
              if (adoquery2.RecordCount <= 0) and (ifsix <>'6') then
              begin
               adoquery1.Append;
               adoquery1.Fields[0].AsString:= code;
               adoquery1.Fields[1].AsString:=ExcelID.Cells[k+1,2].Value;
               adoquery1.Fields[2].AsString:='3';
               adoquery1.Post;
               end;
          end;
          adoquery1.Close;
          ExcelID.quit;
          showmessage('ok');
       end;
    end;