Created attachment 38757 [details] The Format cell is configured here This is my cell value 13-07-2019 Format cell is *dd-mm-yyyy When i try to get the cell value using Cell cell; // this is active cell FormulaEvaluator evaluator; // this is properly assing ConditionalFormattingEvaluator cfEvaluator; DataFormatter formatter = new DataFormatter(); String formattedCellValue = formatter.formatCellValue(cell, evaluator, cfEvaluator); CellType cellType = cell.getCellType(); // this return NUMERIC DateUtil.isCellDateFormatted(cell, cfEvaluator) // this return true String cellFormat = cell.getCellStyle().getDataFormatString(); // this return m/d/yy formattedCellValue value return me 7/13/19 - This is not return me the year in 4 digit
This must return 7/13/2019 but it return 76/13/19. So what could be the issue?
If you open the Excel file on a machine with a US English locale, what does Excel show there? If your formatting is one of the locale-adjusting ones, you'll get what Excel stores in the file, which is US-English
Created attachment 38761 [details] English US Local setting
(In reply to Nick Burch from comment #2) > If you open the Excel file on a machine with a US English locale, what does > Excel show there? > This is US English locale machine only in which i am facing this issue. > If your formatting is one of the locale-adjusting ones, you'll get what > Excel stores in the file, which is US-English
The concern is the format cell is with *dd-mm-yyy the same is attached in the image. And that format is not detected and returning the cell value only dd/mm/yy with 2 digit of the year instead of 4 digit.
Added Details.
Created attachment 38764 [details] Excel File Excel file is attached
Created attachment 38765 [details] RegionSetting Region Setting with date formatting
I have found this stack over flow link - https://stackoverflow.com/questions/34900605/excel-cell-style-issue/34902174#34902174 Is it right solution for this ? if (DateUtil.isCellDateFormatted(cell)) { Date date = cell.getDateCellValue(); System.out.println(date); String dateFmt = ""; if (cell.getCellStyle().getDataFormat() == 14) { //default short date without explicit formatting dateFmt = "dd/mm/yyyy"; //default date format for this } else { //other data formats with explicit formatting dateFmt = cell.getCellStyle().getDataFormatString(); } System.out.println("dateFmt " + dateFmt); String value = new CellDateFormatter(dateFmt).format(date); System.out.println("Date " + value); }