You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by manoranjan <ma...@stlindia.com> on 2013/02/15 10:07:10 UTC
How to get a cell value derived from a formula for excel sheet
using poi
Dear experts,
I am using poi to read excel file.I have a date column using a formula.
I am not getting the exact cell value.
My code is:
switch(cell.getCellType()){
case HSSFCell.CELL_TYPE_NUMERIC :
if(DateUtil.isCellDateFormatted(cell)){
type = getTypeForDate(cell);
}else type = "numeric";break;
case HSSFCell.CELL_TYPE_STRING : type = "string";break;
case HSSFCell.CELL_TYPE_ERROR : type = "error";break;
case HSSFCell.CELL_TYPE_FORMULA :
switch(cell.getCachedFormulaResultType()) {
case HSSFCell.CELL_TYPE_STRING:
HSSFRichTextString str = (HSSFRichTextString)
column.getRichStringCellValue();
if(str != null && str.length() > 0) {
}
break;
case HSSFCell.CELL_TYPE_NUMERIC:
HSSFCellStyle style = (HSSFCellStyle) cell.getCellStyle();
if(style == null) {
} else {
DataFormatter formatter = new
DataFormatter(Locale.getDefault());
String val = formatter.formatRawCellContents(
column.getNumericCellValue(),
style.getDataFormat(),
style.getDataFormatString());
System.out.println("The cell value i am
getting is -->"+val);
}
break;
case HSSFCell.CELL_TYPE_BOOLEAN:
break;
case HSSFCell.CELL_TYPE_ERROR:
break;
}
type = "formula";break;
case HSSFCell.CELL_TYPE_BLANK : type = "blank";break;
case HSSFCell.CELL_TYPE_BOOLEAN : type = "boolean";break;
}
The cell value i am getting is --> 86
The cell value i am getting is --> 114
The cell value i am getting is --> 64
<http://apache-poi.1045710.n5.nabble.com/file/n5712111/date-excel.png>
Help me to solve this problem.
--
View this message in context: http://apache-poi.1045710.n5.nabble.com/How-to-get-cell-formula-value-when-reading-Excel-file-with-EventModel-tp2289629p5712111.html
Sent from the POI - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org