diff options
author | Vladislav Galas <gallon@apache.org> | 2019-01-26 23:19:59 +0000 |
---|---|---|
committer | Vladislav Galas <gallon@apache.org> | 2019-01-26 23:19:59 +0000 |
commit | 53eee01b5dcd28ab894f85403a0e640c054f089f (patch) | |
tree | 34e622dbe24a700f1d13fa7cbf8758e756b35980 /src/java/org/apache | |
parent | 5da229797f116457f2fdefad95306399b9757535 (diff) | |
download | poi-53eee01b5dcd28ab894f85403a0e640c054f089f.tar.gz poi-53eee01b5dcd28ab894f85403a0e640c054f089f.zip |
pulled *Cell.setCellValue(Date) and setCellValue(Calendar) to the common base
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1852254 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org/apache')
-rw-r--r-- | src/java/org/apache/poi/hssf/usermodel/HSSFCell.java | 40 | ||||
-rw-r--r-- | src/java/org/apache/poi/ss/usermodel/CellBase.java | 42 |
2 files changed, 50 insertions, 32 deletions
diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFCell.java b/src/java/org/apache/poi/hssf/usermodel/HSSFCell.java index 7abfe59d20..9292004bb5 100644 --- a/src/java/org/apache/poi/hssf/usermodel/HSSFCell.java +++ b/src/java/org/apache/poi/hssf/usermodel/HSSFCell.java @@ -442,45 +442,21 @@ public class HSSFCell extends CellBase { } /** - * set a date value for the cell. Excel treats dates as numeric so you will need to format the cell as - * a date. + * {@inheritDoc} * - * @param value the date value to set this cell to. For formulas we'll set the - * precalculated value, for numerics we'll set its value. For other types we - * will change the cell to a numeric cell and set its value. + * <p>In HSSF, only the number of days is stored. The fractional part is ignored.</p> + * @see HSSFDateUtil + * @see org.apache.poi.ss.usermodel.DateUtil */ - public void setCellValue(Date value) - { - if(value == null) { - setBlank(); - return; - } - + protected void setCellValueImpl(Date value) { setCellValue(HSSFDateUtil.getExcelDate(value, _book.getWorkbook().isUsing1904DateWindowing())); } /** - * set a date value for the cell. Excel treats dates as numeric so you will need to format the cell as - * a date. - * - * This will set the cell value based on the Calendar's timezone. As Excel - * does not support timezones this means that both 20:00+03:00 and - * 20:00-03:00 will be reported as the same value (20:00) even that there - * are 6 hours difference between the two times. This difference can be - * preserved by using <code>setCellValue(value.getTime())</code> which will - * automatically shift the times to the default timezone. - * - * @param value the date value to set this cell to. For formulas we'll set the - * precalculated value, for numerics we'll set its value. For othertypes we - * will change the cell to a numeric cell and set its value. + * {@inheritDoc} */ - public void setCellValue(Calendar value) - { - if(value == null) { - setBlank(); - return; - } - + @Override + protected void setCellValueImpl(Calendar value) { setCellValue( HSSFDateUtil.getExcelDate(value, _book.getWorkbook().isUsing1904DateWindowing()) ); } diff --git a/src/java/org/apache/poi/ss/usermodel/CellBase.java b/src/java/org/apache/poi/ss/usermodel/CellBase.java index 107f906668..7506ae3419 100644 --- a/src/java/org/apache/poi/ss/usermodel/CellBase.java +++ b/src/java/org/apache/poi/ss/usermodel/CellBase.java @@ -23,6 +23,9 @@ import org.apache.poi.ss.util.CellRangeAddress; import org.apache.poi.ss.util.CellReference; import org.apache.poi.util.Removal; +import java.util.Calendar; +import java.util.Date; + /** * Common implementation-independent logic shared by all implementations of {@link Cell}. * @author Vladislav "gallon" Galas gallon at apache dot org @@ -213,4 +216,43 @@ public abstract class CellBase implements Cell { * @param value the new value to set */ protected abstract void setCellValueImpl(double value); + + @Override + public void setCellValue(Date value) { + if(value == null) { + setBlank(); + return; + } + setCellValueImpl(value); + } + + /** + * Implementation-specific way to set a date value. + * <code>value</code> is guaranteed to be non-null. + * The implementation is expected to adjust the cell type accordingly, so that after this call + * getCellType() or getCachedFormulaResultType() would return {@link CellType#NUMERIC}. + * @param value the new date to set + */ + protected abstract void setCellValueImpl(Date value); + + /** + * {@inheritDoc} + */ + @Override + public final void setCellValue(Calendar value) { + if(value == null) { + setBlank(); + return; + } + setCellValueImpl(value); + } + + /** + * Implementation-specific way to set a calendar value. + * <code>value</code> is guaranteed to be non-null. + * The implementation is expected to adjust the cell type accordingly, so that after this call + * getCellType() or getCachedFormulaResultType() would return {@link CellType#NUMERIC}. + * @param value the new calendar value to set + */ + protected abstract void setCellValueImpl(Calendar value); } |