Forum Discussion

megha_gambhire's avatar
megha_gambhire
Contributor
11 years ago

Incorrect Row count of Excel, if we delete few rows

I have used followign code to read row count from Excel.




 



var app = Sys.OleObject("Excel.Application");



var book = app.Workbooks.Open(fileName);

 



RowCount = app.ActiveSheet.UsedRange.Rows.Count



 



It works first time, for the records added in Excel.



Latter we removed few rows, then try to run the script



here it still displayed old row count, even though we now have less row count.



Any solution on this ?


6 Replies

  • Hi Megha



    you can handle the above problem simply looking for empty or null value in one of the mandatory column, Once found empty or null break the loop and don't wait for Driver.EOF. I hope this will solve your problem



      var mandatoryField;



      while (! Driver.EOF())

      {       

        mandatoryField = aqConvert.VarToStr(Driver.Value(0)); //assuming first column is mandatory.



        if (mandatoryField== null || mandatoryField== "")

        {

          break;

        }



        // Rest of the code here.

        Driver.Next();



      }



    Regards

    Mughees Siddiqui
  • Hi Megha



    Try this



    RowCount = MsExcel.ActiveCell.CurrentRegion.Rows.Count;



    Regards

    Mughees Siddiqui
  • hi Mughees Siddiqui ,



    Yoour solution..display a single count. for n number of rows.



    if i uses


    row = 2

    Driver =
    DDT.ExcelDriver (excel path ..)

     



    while (! Driver.EOF())



    {

    //process datato read ..here i want to rea only added daata in the rows.if the file has 4 rows.. i want to read only 4 data.

    I wan tto read from second row. So i defiened

    row = 2

    }


     



    Driver.Next(); // Goes to the next record



    row++;



    }

    But when few of the data row from excel get reoved, it still start to read the blank data.



    This is my problem.



    Any one has solution ?







     


     
  • This is the difference between testcomplete and other tool....Testcomplete support team hardly able to answer the queries... 
  • This is biggest bug with testcomplete.... as its giving incorrect Excel count Number.

    How people paying for this buggy tool ?