1

I am writing dates in rows in xlsx file with Apache POI scala.

It is writing in file and showing format as Custom date but values are not reflecting as Custom date until I am clicking double on that cell. After double click it is converting as custom date.

Can someone please tell me why this cell formatting is not reflecting on values. I have tried all ways available on stack overflow for formatting in apache POI.

            val cellStyle = workbook.createCellStyle();
            val df = workbook.createDataFormat();
            cellStyle.setDataFormat(df.getFormat("MMM-yy"))
            cell.setCellValue(r)
            cell.setCellStyle(cellStyle)

Excel value show

pme
  • 14,156
  • 3
  • 52
  • 95

1 Answers1

1

For completion:

POI provides different setCellValue methods for different formats. See the Java Docs.

Depending on the datatype you have POI will create the according Excel Cell Type.

So in your case you have the following possibilities:

setCellValue(java.util.Date value)
setCellValue(java.time.LocalDateTime value)
setCellValue(java.time.LocalDate value)
setCellValue(java.util.Calendar value)

So your cell.setCellValue(r) must be one of the above if you want a Date Cell.

pme
  • 14,156
  • 3
  • 52
  • 95