在SoapUI中使用Groovy脚本从xlsx文件读取值

时间:2019-01-17 13:47:55

标签: groovy apache-poi soapui

我使用以下脚本从xlsx文件中读取值:

import java.io.File;
import java.io.FileInputStream;
import java.util.Iterator;
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;

String filepath = "D:\\testdata\\TestData.xlsx"
String sheetName = "Sheet1"
FileInputStream fis = new FileInputStream(new File(filepath))

Workbook wb = WorkbookFactory.create(fis)
Sheet sh = wb.getSheet(sheetName)

Iterator itrRow = sh.rowIterator()
while(itrRow.hasNext())
{
    Row row = itrRow.next()
    for(Cell cell : row)
    {
        switch(cell.getCellType())
        {
            case Cell.CELL_TYPE_NUMERIC:
                log.info cell.getNumericCellValue()
                break;
            default:
                log.info cell.getRichStringCellValue()
        }       
    }   
}

fis.close()
wb.close()

我将poi-4.0.1.jar文件添加到bin/ext文件夹中,但是在执行测试步骤时收到以下错误消息:

  

java.io.IOException:java.lang.ClassNotFoundException:   org.apache.poi.xssf.usermodel.XSSFWorkbookFactory

1 个答案:

答案 0 :(得分:1)

我的建议是保持简单并使用Fillo jar。它可以触发yo xls查询并获取记录集。 谢谢, 尼罗什