Bug 66899 - Get cell value return dd/mm/yy when cell format is *dd-mm-yyyy. The expectation need to return year in 4 digit
Summary: Get cell value return dd/mm/yy when cell format is *dd-mm-yyyy. The expectati...
Status: NEW
Alias: None
Product: POI
Classification: Unclassified
Component: POI Overall (show other bugs)
Version: 5.2.3-FINAL
Hardware: PC All
: P2 major (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-08-14 08:28 UTC by hasmukh ginoya
Modified: 2023-08-14 11:29 UTC (History)
0 users



Attachments
The Format cell is configured here (96.93 KB, image/jpeg)
2023-08-14 08:28 UTC, hasmukh ginoya
Details
English US Local setting (77.18 KB, image/jpeg)
2023-08-14 10:00 UTC, hasmukh ginoya
Details
Excel File (9.33 KB, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet)
2023-08-14 10:22 UTC, hasmukh ginoya
Details
RegionSetting (73.51 KB, image/jpeg)
2023-08-14 10:30 UTC, hasmukh ginoya
Details

Note You need to log in before you can comment on or make changes to this bug.
Description hasmukh ginoya 2023-08-14 08:28:47 UTC
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
Comment 1 hasmukh ginoya 2023-08-14 08:34:10 UTC
This must return 7/13/2019 but it return 76/13/19.
So what could be the issue?
Comment 2 Nick Burch 2023-08-14 09:52:02 UTC
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
Comment 3 hasmukh ginoya 2023-08-14 10:00:41 UTC
Created attachment 38761 [details]
English US Local setting
Comment 4 hasmukh ginoya 2023-08-14 10:01:42 UTC
(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
Comment 5 hasmukh ginoya 2023-08-14 10:02:56 UTC
(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
Comment 6 hasmukh ginoya 2023-08-14 10:05:02 UTC
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.
Comment 7 hasmukh ginoya 2023-08-14 10:20:13 UTC
Added Details.
Comment 8 hasmukh ginoya 2023-08-14 10:22:26 UTC
Created attachment 38764 [details]
Excel File

Excel file is attached
Comment 9 hasmukh ginoya 2023-08-14 10:30:29 UTC
Created attachment 38765 [details]
RegionSetting

Region Setting with date formatting
Comment 10 hasmukh ginoya 2023-08-14 11:29:10 UTC
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);

   }