POI: Excel double click changes the date format

Viewed 48

I am facing one strange issue. I have written a program in java using apache poi 5.2.2 which reads csv file and writes in to excel sheet(.xlsx).In that csv file there is one date column, the format is in mm-dd-yyyy(04-25-2022). my program converts this format to d/mmm/yyyy format. When I run my program it creates new xlsx sheet. But when I open this file the date column still shows in mm-dd-yyyy(04-25-2022) format. But if I double click on that cell it changes it to d/mmm/yyyy (25/Apr/2022). Is there any function in java? Below is my code. Is there any solution or this is excel issue.

String value = null;
CellStyle style = workBook.createCellStyle();
CreationHelper createHelper = workBook.getCreationHelper();
style.setDataFormat(createHelper.createDataFormat().getFormat("d/MMM/yyyy"));

BufferedReader br = new BufferedReader(new FileReader(csvFileAddress));
while ((currentLine = br.readLine()) != null) {
    String str[] = currentLine.split(",");
    RowNum++;

    XSSFRow currentRow=sheet.createRow(RowNum);
    for (int i = 0; i < str.length; i++) {
        value = str[i];
        Cell cell = currentRow.createCell(i);
        cell.setCellValue(value);
        cell.setCellStyle(style);
    }
 }

FileOutputStream fileOutStream =  new FileOutputStream(xlsxFileAddress);
0 Answers
Related