Search before asking
Fesod version
current main (50a6b5b)
JDK version
Temurin 25 (code path is version-independent, affects 8+)
Operating system
Linux (not OS-specific)
Steps To Reproduce
Writing a Calendar value to a CsvCell via the POI Cell API silently produces an empty field instead of the date.
Calendar cal = Calendar.getInstance();
cal.set(2024, Calendar.JANUARY, 15, 12, 30, 45);
cal.set(Calendar.MILLISECOND, 0);
try (Writer writer = Files.newBufferedWriter(csvFile.toPath(), StandardCharsets.UTF_8)) {
CsvWorkbook workbook = new CsvWorkbook(writer, null, false, false, StandardCharsets.UTF_8, false);
CsvSheet sheet = (CsvSheet) workbook.createSheet();
CsvRow row = (CsvRow) sheet.createRow(0);
Cell cell = row.createCell(0, CellType.NUMERIC);
cell.setCellValue(cal);
sheet.close();
}
// csvFile content is an empty field instead of "2024-01-15 12:30:45"
Current Behavior
The CSV cell is written as an empty field. The Calendar value is silently lost — no exception is thrown.
Expected Behavior
The cell should be written as a date (2024-01-15 12:30:45 by default), the same way setCellValue(java.util.Date) and setCellValue(java.time.LocalDateTime) behave on a CsvCell.
Anything else?
Root cause: CsvCell.setCellValueImpl(Calendar) sets dateValue and cellType = NUMERIC but, unlike its sibling setters, does not set numericCellType = NumericCellTypeEnum.DATE:
https://github.com/apache/fesod/blob/main/fesod-sheet/src/main/java/org/apache/fesod/sheet/metadata/csv/CsvCell.java#L186-L193
@Override
protected void setCellValueImpl(Calendar value) {
if (value == null) {
return;
}
this.dateValue = LocalDateTime.ofInstant(value.toInstant(), ZoneId.systemDefault());
this.cellType = CellType.NUMERIC;
// missing: this.numericCellType = NumericCellTypeEnum.DATE;
}
The sibling Date setter (a few lines above) and LocalDateTime setter both set it:
this.cellType = CellType.NUMERIC;
this.numericCellType = NumericCellTypeEnum.DATE;
In CsvSheet.buildCellValue the NUMERIC branch dispatches on csvCell.getNumericCellType() == NumericCellTypeEnum.DATE; when it is not set, the cell takes the number branch, finds numberValue is null, and returns null, producing an empty field.
Adding the missing line fixes it:
this.numericCellType = NumericCellTypeEnum.DATE;
Are you willing to submit a PR?
Search before asking
Fesod version
current main (50a6b5b)
JDK version
Temurin 25 (code path is version-independent, affects 8+)
Operating system
Linux (not OS-specific)
Steps To Reproduce
Writing a
Calendarvalue to aCsvCellvia the POICellAPI silently produces an empty field instead of the date.Current Behavior
The CSV cell is written as an empty field. The
Calendarvalue is silently lost — no exception is thrown.Expected Behavior
The cell should be written as a date (
2024-01-15 12:30:45by default), the same waysetCellValue(java.util.Date)andsetCellValue(java.time.LocalDateTime)behave on aCsvCell.Anything else?
Root cause:
CsvCell.setCellValueImpl(Calendar)setsdateValueandcellType = NUMERICbut, unlike its sibling setters, does not setnumericCellType = NumericCellTypeEnum.DATE:https://github.com/apache/fesod/blob/main/fesod-sheet/src/main/java/org/apache/fesod/sheet/metadata/csv/CsvCell.java#L186-L193
The sibling
Datesetter (a few lines above) andLocalDateTimesetter both set it:In
CsvSheet.buildCellValuetheNUMERICbranch dispatches oncsvCell.getNumericCellType() == NumericCellTypeEnum.DATE; when it is not set, the cell takes the number branch, findsnumberValueisnull, and returnsnull, producing an empty field.Adding the missing line fixes it:
Are you willing to submit a PR?