Forum Discussion

Banking's avatar
Banking
New Contributor
8 years ago

No Such property: Workbook for class

import jxl.*

def f = new File("E:\\xyz\\data.xls")
def wk = Workbook.getWorkbook(f)
def s1 = wk.getSheet(0)
def rows = s1.getRows()

 

the below error is being dispalyed

groovy:lang.MissingPropertyException:No such property: Workbook for class: Script3 error at line:3

2 Replies

  • avidCoder's avatar
    avidCoder
    Super Contributor

    I'd suggest you to use apache poi jar files inside SOAPUI HOME/bin/ext .. And use below code to get the rows:-

     

    import java.io.FileInputStream;
    import java.io.FileNotFoundException;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.io.InputStream;
    import org.apache.poi.ss.usermodel.Cell;
    import org.apache.poi.ss.usermodel.Row;
    import org.apache.poi.ss.usermodel.Sheet;
    import org.apache.poi.ss.usermodel.Workbook;
    import org.apache.poi.ss.usermodel.WorkbookFactory;
    import org.apache.poi.ss.usermodel.CellStyle;
    
    def projectPath = context.expand('${projectDir}') //Where your project resides main project properties 
    def path = projectPath + "/userInput.xls" //your inputsheet name
    
    FileInputStream inputStream = new FileInputStream(path)
    
    Workbook wb = WorkbookFactory.create(inputStream)
    Sheet sheet1 = wb.getSheet("Sheet Name")
    int rows = sheet1.getLastRowNum();
    log.info(rows)
    
    It should print you the number of rows.

    Hope, it works for you.

     

    You like the reply. Learn how to give kudos.