如何从excel获取整数值并存储在Soap UI属性步骤中

问题描述 投票:-1回答:1

我在excel中有一个保存数值的数据,当我将相同的值从Excel发送到Soap UI属性时,它的值将转换为如下所示的字符串:

在Excel中:数据列的值为200在Soap UI属性中:数据字段的值已更改为200.0

有人可以帮助我在Soap UI属性中获得相同的数值吗?

FileInputStream fis = new FileInputSTream("Excel File Location");
XSSFWorkbook workbook = new XSSFWorkbook(fis);
XSSFSheet Sheet = new XSSFSheet("SheetName");
int totalRows = sheet.getPhysicalNumberOfRows();
testRunner.testCase.SetPropertyvalue("totalRows",totalRows.toString())
def int totalcolumn = sheet.getrow(0).getLastCellNum();
def propdataarray = []
def dataArray = []
def rowIndex = testrunner.testCase.getPropertyValue("RowIndex").toInteger();
if(rowIndex<totalRows)
{

    for(int i = 0;i<totalcolumn;i++)
    {

        colData = sheet.getRow(0).getCell(i).toString();
        propdataarray.add(colData)

        testData = sheet.getRow(rowIndex).getCell(i).toString();
        dataArray.add(testData);
        testRunner.testCase.getTestStepByName("Properties").setPropertyValue(propdataarray.get[i],dataArray.get[i]) 

        } 
    }

    else
    {
        com.eviware.soapui.support.UISupport.showInfoMessage("Please provide the appropriate RowIndex number in the test case custom properties")
        }

java groovy apache-poi soapui
1个回答
0
投票
[正如Axel Richter所说,请使用DataFormatter.formatCellValue来更正源中的值。或者,您可以使用与Groovy一起很好地为您处理的抽象script

如您所说,SoapUI仅将字符串用作属性值。如果要在接收/使用侧更正它,可以使用此方法:

def propVal = '200.0' assert propVal instanceof java.lang.String println propVal.toFloat().toInteger() assert propVal.toFloat().toInteger() instanceof java.lang.Integer

通常最好在源处更正格式(在将其存储在属性中之前。)>        
© www.soinside.com 2019 - 2024. All rights reserved.