import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
+import java.util.Map;
import org.apache.poi.ss.SpreadsheetVersion;
import org.apache.poi.ss.formula.FormulaParseException;
*/
@Override
public void setCellValue(Date value) {
+ if(value == null) {
+ setCellType(Cell.CELL_TYPE_BLANK);
+ return;
+ }
+
boolean date1904 = getSheet().getWorkbook().isDate1904();
setCellValue(DateUtil.getExcelDate(value, date1904));
}
*/
@Override
public void setCellValue(Calendar value) {
+ if(value == null) {
+ setCellType(Cell.CELL_TYPE_BLANK);
+ return;
+ }
+
boolean date1904 = getSheet().getWorkbook().isDate1904();
setCellValue( DateUtil.getExcelDate(value, date1904 ));
}
* the Workbook.</p>
*
* <p>To change the style of a cell without affecting other cells that use the same style,
- * use {@link org.apache.poi.ss.util.CellUtil#setCellStyleProperties(Cell, Map)}</p>
+ * use {@link org.apache.poi.ss.util.CellUtil#setCellStyleProperties(Cell, Map<String,Object>)}</p>
*
* @param style reference contained in the workbook.
* If the value is null then the style information is removed causing the cell to used the default workbook style.
}
/**
- * Copy cell value, formula, and style, from srcCell per cell copy policy
+ * Copy cell value, formula and style, from srcCell per cell copy policy
* If srcCell is null, clears the cell value and cell style per cell copy policy
*
* This does not shift references in formulas. Use {@link org.apache.poi.xssf.usermodel.helpers.XSSFRowShifter} to shift references in formulas.
*
- * @param srcCell
- * @param policy
+ * @param srcCell The cell to take value, formula and style from
+ * @param policy The policy for copying the information, see {@link CellCopyPolicy}
* @throws IllegalArgumentException if copy cell style and srcCell is from a different workbook
*/
@Beta
* the XSSFWorkbook.</p>
*
* <p>To change the style of a cell without affecting other cells that use the same style,
- * use {@link org.apache.poi.ss.util.CellUtil#setCellStyleProperties(Cell, Map)}</p>
+ * use {@link org.apache.poi.ss.util.CellUtil#setCellStyleProperties(Cell, java.util.Map<String, Object>)}</p>
*
* @param style reference contained in the workbook.
* If the value is null then the style information is removed causing the cell to used the default workbook style.
*/
@Override
public Date getDateCellValue() {
- int cellType = getCellType();
- if (cellType == CELL_TYPE_BLANK) {
+ if (getCellType() == CELL_TYPE_BLANK) {
return null;
}
*/
@Override
public void setCellValue(Date value) {
+ if(value == null) {
+ setCellType(Cell.CELL_TYPE_BLANK);
+ return;
+ }
+
boolean date1904 = getSheet().getWorkbook().isDate1904();
setCellValue(DateUtil.getExcelDate(value, date1904));
}
*/
@Override
public void setCellValue(Calendar value) {
+ if(value == null) {
+ setCellType(Cell.CELL_TYPE_BLANK);
+ return;
+ }
+
boolean date1904 = getSheet().getWorkbook().isDate1904();
setCellValue( DateUtil.getExcelDate(value, date1904 ));
}
import static org.junit.Assert.assertEquals;
import java.io.IOException;
+import java.util.Calendar;
+import java.util.Date;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.ss.ITestDataProvider;
assertEquals("???<>\t\n\u00a0 &\"POI\'\u2122", wb2.getSheetAt(0).getRow(0).getCell(0).getStringCellValue());
wb2.close();
}
+
+ @Test
+ public void testSetNullValues() {
+ Workbook wb = _testDataProvider.createWorkbook();
+ Cell cell = wb.createSheet("test").createRow(0).createCell(0);
+
+ cell.setCellValue((Calendar)null);
+ cell.setCellValue((Date)null);
+ cell.setCellValue((String)null);
+ cell.setCellValue((RichTextString) null);
+ cell.setCellValue((String)null);
+ }
}