Forum Discussion

kaiiii's avatar
kaiiii
Regular Contributor
5 years ago
Solved

How can I Count the row of test data in my excel sheet.

How can I Count the row of test data in my excel sheet.

Like:

 Project.Variable.VariableName.IsEOF  ---> used to check sheet is empty or not

 Project.Variable.VariableName.ColumnCount --> used to check no of column in the sheet

similarly,

how can i find out the no of total rows in a sheet

  • There is no function/method/property of the DB Table variable type that will give you the explicit row count.  So, you'll need to write code to do so.

    function sheetText(){
        var rowCount
        rowCount = 0
        while (!Project.Variables.VariableName.IsEOF()) {
            rowCount++
            Project.Variables.VariableName.Next()
        }
        Log.Message(rowCount)
    }

4 Replies

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor

    There is no function/method/property of the DB Table variable type that will give you the explicit row count.  So, you'll need to write code to do so.

    function sheetText(){
        var rowCount
        rowCount = 0
        while (!Project.Variables.VariableName.IsEOF()) {
            rowCount++
            Project.Variables.VariableName.Next()
        }
        Log.Message(rowCount)
    }
  • sethir's avatar
    sethir
    Frequent Visitor

    kaiiii  You can use follwoing groovy script to get number of rows in an excel sheet-

    ---------------------------------------------------------------------------------------------

    import com.eviware.soapui.support.XmlHolder
    import jxl.*
    import jxl.write.*

    // DECLARE THE VARIABLES
    def myTestCase = context.testCase //myTestCase contains the test case
    def size 
    Workbook workbook1 = Workbook.getWorkbook(new File("C:\\Users\\sethir\\files\\numbers.xls")) //file containing the data
    Sheet sheet1 = workbook1.getSheet("orders")// You can also provide 0 instead of sheet name. It will read first sheet from the workbook
    size= sheet1.getRows().toInteger() //get the number of rows, each row is a data set
    log.info ("total rows"+ size);

    • tristaanogre's avatar
      tristaanogre
      Esteemed Contributor

      TestComplete does not support Groovy.  That's a SoapUI solution.

      • sonya_m's avatar
        sonya_m
        SmartBear Alumni (Retired)

        Hi kaiiii , have you tried using the approach that tristaanogre suggested? Let us know whether you situation is resolved.