Date in Cell formatted as Date not recognized as Date
<p>I am trying to use Apache's Java POI to add Dates to a spreadsheet. However, I am ending up with the dates in the date-formatted cells not being recognized as dates by the cell but as Strings. Yet, when I open the spreadsheet subsequently, nothing more than it takes is a click into the cell - i.e. editing it while not even making an effective change - and the date format is recognized automatically. How can I make my program conduct this very last step without me needing to interfere? Thank you very much, in advance!</p>

<pre><code>    CreationHelper creationHelper = wb.getCreationHelper();
    XSSFCellStyle cellStyleDate = wb.createCellStyle();

    LocalDate start = LocalDate.of(2000, 1, 1);
    LocalDate end = LocalDate.of(2000, 12, 31);

    cellStyleDate.setDataFormat(creationHelper.createDataFormat().getFormat("dd.mm.yyyy"));
    int i = 1;
    for (LocalDate date = start; date.isBefore(end); date = date.plusDays(1)) {

        // wb.getSheetAt(0).createRow(i).createCell(0).setCellValue(date);
        wb.getSheetAt(0).createRow(i).createCell(0).setCellValue(date.toString());
        // wb.getSheetAt(0).createRow(i).createCell(0).setCellValue(date.getDayOfMonth() + "." + date.getMonthValue() + "." + date.getYear());

        wb.getSheetAt(0).getRow(i).getCell(0).setCellStyle(cellStyleDate);
        i++;
    }
</code></pre>