Coder Social home page Coder Social logo

Comments (9)

ozlerhakan avatar ozlerhakan commented on August 22, 2024 1

Thanks @vaquarkhan , Now I see that there is a style in these columns and poi by itself gets their format index as 14 and theirs format string as 'm/d/yy'. You can debug all the cells of an excel file via https://github.com/ozlerhakan/poiji#debug-cells-formats.

What you need to do is you can convert the format string of the format index via https://github.com/ozlerhakan/poiji#modify-cells-formats.

You can use these steps:

PoijiNumberFormat numberFormat = new PoijiNumberFormat();
numberFormat.putNumberFormat((short) 14, "dd/mm/yyyy");

PoijiOptions options = PoijiOptions.PoijiOptionsBuilder.settings()
        .poijiNumberFormat(numberFormat)
        .build();

and here it is:

Screen Shot 2021-11-12 at 9 08 34 AM

BTW when I opened it up on my local the columns look like this:

Screen Shot 2021-11-12 at 8 25 30 AM

from poiji.

ozlerhakan avatar ozlerhakan commented on August 22, 2024

Let me understand clearly, you have a date column and you map it as String as follows:

@ExcelCellName("COLUMN_DATE")
String date;

and you get the value as "3/30/21" right?

Normally It shouldn't be this way since it's of type String. Could you give me examples?

from poiji.

vaquarkhan avatar vaquarkhan commented on August 22, 2024

I have date column in xlsx
image

Now here is my POJO

  @ExcelCell(21)
String startDate;
@ExcelCell(22)
String endDate;

Service code :
List resource = Poiji.fromExcel(new File(SAMPLE_XLSX_FILE_PATH), Resource.class);

When i am debugging found inside list value is change once read by Poiji ,its working fine with POI api

Once list populated i am sending into Springboot Repository and inside calling JDBC template to insert records
So when going to insert i am converting this String date to Java.sql.date and insert.

SInce Poiji reading 3/30/21 conversion adding wrong values into db
image

Following method is my conversion method

private  static java.sql.Date stringToDate(String str){
    if (null==str) return null;
    if (str.isBlank()||str.isEmpty()) return null;
    SimpleDateFormat format = new SimpleDateFormat("MM/dd/yyyy");//yyyyMMdd
    Date parsed = null;
    try {
	    parsed = format.parse(str);
    } catch (ParseException e) {
	  // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return new java.sql.Date(parsed.getTime());
  }


public static void main (String args[]) {
    String str="3/30/2021";
    java.sql.Date date=stringToDate( str);
    System.out.println(date);
}

from poiji.

ozlerhakan avatar ozlerhakan commented on August 22, 2024

Could you please share with me an excel file with those few examples?

from poiji.

vaquarkhan avatar vaquarkhan commented on August 22, 2024

You can try with this data
image

from poiji.

ozlerhakan avatar ozlerhakan commented on August 22, 2024

I need your sample excel file @vaquarkhan , otherwise I tried but couldn't produce this case for the date values like '3/30/2021'

from poiji.

vaquarkhan avatar vaquarkhan commented on August 22, 2024

sample.xlsx
here you go

from poiji.

vaquarkhan avatar vaquarkhan commented on August 22, 2024

Thanks let me check

from poiji.

ozlerhakan avatar ozlerhakan commented on August 22, 2024

you can use 3.1.3 of Poiji @vaquarkhan , thank you for your contribution :)

from poiji.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.