Reputation: 3
I am trying to read an excel file , which contains only one column , and its an array of json , I am not able to read it by apache-poi in the form of string .
XSSFWorkbook workbook = new XSSFWorkbook(file);
XSSFSheet worksheet = workbook.getSheetAt(0);
int index = 0;
for (index = 0; index < worksheet.getPhysicalNumberOfRows(); index++) {
if (index > 0) {
XSSFRow row = worksheet.getRow(index);
String b = row.getCell(0).getStringCellValue();
System.out.println(b);
}
}
This code is not returning the value of the columns in string form. Please tell me - how can I read the col values in string as it is?
Upvotes: 0
Views: 351
Reputation: 159
I solved your problem once try this
HSSFWorkbook wb=new HSSFWorkbook(file);
HSSFSheet sheet=wb.getSheetAt(0);
FormulaEvaluator formulaEvaluator=wb.getCreationHelper().createFormulaEvaluator();
for(Row row: sheet)
{
for(Cell cell: row)
{
switch(formulaEvaluator.evaluateInCell(cell).getCellType())
{
case Cell.CELL_TYPE_NUMERIC:
System.out.print(cell.getNumericCellValue()+ "\t\t");
break;
case Cell.CELL_TYPE_STRING:
System.out.print(cell.getStringCellValue()+ "\t\t");
break;
}
}
System.out.println();
}
I took the input in .xls file like this
and this is the output
Upvotes: 1