Issue with excel sheet while trying to fetch the values from groovy script

后端 未结 2 583
滥情空心
滥情空心 2021-01-26 16:08

If i place getCell(0,0) in String reqTagName = sheet1.getCell(0,0).getContents() for the below code then, it is only executing the first value from the sheet. B

2条回答
  •  天涯浪人
    2021-01-26 16:49

    Try this code change below and let me know if it worked :

    import com.eviware.soapui.support.XmlHolder
    import java.io.File
    import java.io.IOException
    import jxl.*
    import jxl.read.biff.BiffException
    import jxl.write.*
    import jxl.write.Label
    log.info("Testing Started")
    def reqOperationName = "getInsuranceDetails_1_FTC_005"
    def inputDataFileName = "D:/SOAP UI Pro/MPI.xls"
    def inputDataSheetName = "MPI"
    Workbook workbook = Workbook.getWorkbook(new File(inputDataFileName))
    Sheet  sheet1 = workbook.getSheet(inputDataSheetName)
    
    
    def myList = new ArrayList();
    def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)
    String xmlResponse = reqOperationName+"#Request"
    def reqholder = groovyUtils.getXmlHolder(xmlResponse)
    try{
        rowcount = sheet1.getRows()
        colcount = sheet1.getColumns()
    
        for(Row in 1..rowcount-1){
    
        String reqTagName = sheet1.getCell(0,0).getContents()
    
        def TagCount = reqholder["count(//*:"+reqTagName+")"]
    
        if(TagCount!=0){
            String reqTagValue = sheet1.getCell(0,Row).getContents()
            if(reqTagValue!=null && !reqTagValue.isEmpty() && reqTagValue!="")
                    {
                        reqholder = groovyUtils.getXmlHolder(xmlResponse)
                        log.info "extracted value : " + reqTagValue
                    reqholder.setNodeValue("//*:"+reqTagName, reqTagValue)
                    reqholder.updateProperty()        
                    log.info "node value : " + reqholder.getNodeValue("//*:"+reqTagName)
                    //test the request
                    testRunner.runTestStepByName(reqOperationName)
                    reqholder = groovyUtils.getXmlHolder(reqOperationName+"#Response")
                    myList.add(reqholder.getPrettyXml().toString())
                    log.info myList[Row-1]
                    }                      
        }
    
        }
    }
    catch (Exception e) {log.info(e)}
    finally{
        workbook.close()
    }
    Workbook existingWorkbook = Workbook.getWorkbook(new File(inputDataFileName));
    WritableWorkbook workbookCopy = Workbook.createWorkbook(new File(inputDataFileName), existingWorkbook);
    
    try
    {
        WritableSheet sheetToEdit = workbookCopy.getSheet(inputDataSheetName);
        WritableCell cell;
        for (int i =1;i

提交回复
热议问题