poi-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serouja <sero...@hotmail.com>
Subject Search in Sheet
Date Sun, 30 Oct 2011 09:35:13 GMT
Dear All, please I need your help in my code (first sorry for my english,
second I'm still a beginner in java,,sorry)

I'm trying to search for a String value in a column which contains formula
values and return equivalent values in the same row but different column.

my method code is below:

public void getCellValue(String sheetName, String sSearch,int iCol, int
iRCol){
String cellValue = null;
HSSFSheet sheet = workbook.getSheet(sheetName);
for (Row r:sheet){
Cell c = r.getCell(iCol);
if (c != null){
if (c.getCellType() == Cell.CELL_TYPE_FORMULA || c.getCellType() ==
Cell.CELL_TYPE_STRING){
try {
if (c.getStringCellValue().toUpperCase().contains(sSearch)){
cellValue = r.getCell(iRCol).getStringCellValue();
}
} catch (Exception ex){

}
}
}
}
return cellValue;
}

-- The problem that in the column which I'm searching there are cell formula
which returns "Blank" value, so I keep receiving this error
"java.lang.IllegalStateException: Cannot get a text value from a numeric
formula cell", even I rapped my code with Try/Catch, but still not receiving
what I need, please help!! 

Thanks Alot.

--
View this message in context: http://apache-poi.1045710.n5.nabble.com/Search-in-Sheet-tp4949824p4949824.html
Sent from the POI - User mailing list archive at Nabble.com.
Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message