Reputation: 5671
I use following script to read values from xlsx
file:
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()
I added poi-4.0.1.jar
file to bin/ext
folder, but got following error message when test step is executed:
java.io.IOException: java.lang.ClassNotFoundException: org.apache.poi.xssf.usermodel.XSSFWorkbookFactory
Upvotes: 2
Views: 2769
Reputation: 103
My advice would be to keep it simple and use Fillo jar.It allows you to fire query yo xls and get recordset. Thanks, Nilesh
Upvotes: 1