mirror of https://github.com/apache/poi.git
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
This commit is contained in:
parent
5da229797f
commit
53eee01b5d
|
@ -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()) );
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -171,54 +171,20 @@ public class SXSSFCell extends CellBase {
|
|||
}
|
||||
|
||||
/**
|
||||
* Converts the supplied date to its equivalent Excel numeric value and sets
|
||||
* that into the cell.
|
||||
* <p>
|
||||
* <b>Note</b> - There is actually no 'DATE' cell type in Excel. In many
|
||||
* cases (when entering date values), Excel automatically adjusts the
|
||||
* <i>cell style</i> to some date format, creating the illusion that the cell
|
||||
* data type is now something besides {@link CellType#NUMERIC}. POI
|
||||
* does not attempt to replicate this behaviour. To make a numeric cell
|
||||
* display as a date, use {@link #setCellStyle(CellStyle)} etc.
|
||||
*
|
||||
* @param value the numeric 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 numerics cell and set its value.
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void setCellValue(Date value) {
|
||||
if(value == null) {
|
||||
setBlank();
|
||||
return;
|
||||
}
|
||||
|
||||
protected void setCellValueImpl(Date value) {
|
||||
boolean date1904 = getSheet().getWorkbook().isDate1904();
|
||||
setCellValue(DateUtil.getExcelDate(value, date1904));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set a date value for the cell. Excel treats dates as numeric so you will need to format the cell as
|
||||
* a date.
|
||||
* <p>
|
||||
* 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.
|
||||
* </p>
|
||||
*
|
||||
* @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}
|
||||
*/
|
||||
@Override
|
||||
public void setCellValue(Calendar value) {
|
||||
if(value == null) {
|
||||
setBlank();
|
||||
return;
|
||||
}
|
||||
|
||||
protected void setCellValueImpl(Calendar value) {
|
||||
boolean date1904 = getSheet().getWorkbook().isDate1904();
|
||||
setCellValue( DateUtil.getExcelDate(value, date1904 ));
|
||||
}
|
||||
|
|
|
@ -776,47 +776,19 @@ public final class XSSFCell 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.
|
||||
*
|
||||
* @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.
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void setCellValue(Date value) {
|
||||
if(value == null) {
|
||||
setBlank();
|
||||
return;
|
||||
}
|
||||
|
||||
protected void setCellValueImpl(Date value) {
|
||||
boolean date1904 = getSheet().getWorkbook().isDate1904();
|
||||
setCellValue(DateUtil.getExcelDate(value, date1904));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a date value for the cell. Excel treats dates as numeric so you will need to format the cell as
|
||||
* a date.
|
||||
* <p>
|
||||
* 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.
|
||||
* </p>
|
||||
*
|
||||
* @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}
|
||||
*/
|
||||
@Override
|
||||
public void setCellValue(Calendar value) {
|
||||
if(value == null) {
|
||||
setBlank();
|
||||
return;
|
||||
}
|
||||
|
||||
protected void setCellValueImpl(Calendar value) {
|
||||
boolean date1904 = getSheet().getWorkbook().isDate1904();
|
||||
setCellValue( DateUtil.getExcelDate(value, date1904 ));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue