dhatim / fastexcel

Generate and read big Excel files quickly
Other
647 stars 116 forks source link

Problem parsing date , taking some dates as number #328

Open AnantJain9968 opened 10 months ago

AnantJain9968 commented 10 months ago

Hi , I am trying to fetch excel file and it is taking some dates as numbers for ex. 12/11/2024 is being taken as number value while 23/11/2024 is working fine taking as date value How can I ensure it takes the date correctly and if there is any range of dates for which it takes as number value or identified issue
Please help I am writing the code and attaching the excel file

try (FileInputStream Xlsfile = new FileInputStream(scriptDefinitionFile); ReadableWorkbook wb = new ReadableWorkbook(Xlsfile)) { Sheet sheet = wb.getFirstSheet(); List rows = sheet.read(); int j = 0; for (org.dhatim.fastexcel.reader.Row row : rows) {

Demo.xlsx

ezand commented 7 months ago

I've also encountered this one and tried to dig a bit into it. For me it seems like the problem lies in this piece of code:

if ("numFmt".equals(reader.getLocalName())) {
    String formatCode = reader.getAttributeRequired("formatCode");
    fmtIdToFmtString.put(reader.getAttributeRequired("numFmtId"), formatCode);
} else if (insideCellXfs.get() && reader.isStartElement("xf")) {
    fmtIdList.add(reader.getAttribute ("numFmtId"));
}

The problem doesn't seem to be the code itself, rather the lacking information in (OpenXml files) styles.xml. Excel has some built in number formats, so in some cases the formatCode just might not be present.

I need date formatting to work, so I'll see if I get some time to dig into it and maybe prepare a pull request if I come to a solution.

ezand commented 7 months ago

@AnantJain9968 My PR is now merged and changes are available in 0.16.4, hopefully it will solve your issue 🤞