Bug 41161 - getDateCellValue() doesn't deal with formula cells returning a date.
Summary: getDateCellValue() doesn't deal with formula cells returning a date.
Status: RESOLVED LATER
Alias: None
Product: POI
Classification: Unclassified
Component: HSSF (show other bugs)
Version: unspecified
Hardware: All other
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-12-12 09:09 UTC by Adam Buchbinder
Modified: 2011-02-25 17:16 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Adam Buchbinder 2006-12-12 09:09:48 UTC
It's possible to use formulas to deal with dates; for instance, the first cell
in a column of dates will be set, and the rest of them will be set by reference,
so that only one cell needs to be modified.

However, getDateCellValue() doesn't test for formula cells, so that when one
tries to pull a date from a cell set in this manner, it will default to an
attempt to get the cell's numeric value and use that, which will not give the
correct results.

The relevant class is org.apache.poi.hssf.usermodel.HSSFCell, and this issue is
present in SVN revision 486227.
Comment 1 Amol Deshmukh 2006-12-12 12:40:54 UTC
If you have last saved the file using an external application the following
should give you the expected date value:

HSSFDateUtil.getJavaDate(value);

However, if the cell value was last edited using POI, you will not get the
correct "date" value. This is because until the file is opened by an external
application the formula will not be evaluated and hence the "stored" value will
not reflect the expected value. You could try to use the HSSFFormulaEvaluator to
evaluate the formula cell and then use HSSFDateUtil.getJavaDate to convert the
value to a Java Date.

If this does not resolve your problem,  please post some code that illustrates
the problem.
Comment 2 Nick Burch 2011-02-25 17:16:04 UTC
This has been fixed at some point in the last 4 years, and HSSFCell can get formula date values just fine now.