A library that can fill Java object with data decl

2019-06-08 01:07发布

问题:

I'm wondering if there is any tool/library that would fill Java objects with data from Excel spreadsheet.

My idea is like you have an Excel spreadsheet that has first line that contains column names with mirroring names of field in target Java object. All other lines are data, so the library would take the class used for instantiation of objects and fill the list with as many instances as there are lines in Excel file.

Is there something like this around?

回答1:

You will have to code your own utility for doing this task. There are helpful libraries out there:

  • Apache POI - http://poi.apache.org/spreadsheet/index.html
  • JExcel API - http://www.andykhan.com/jexcelapi/tutorial.html


回答2:

Apache POI can be used to extract data from an Excel sheet and Apache Commons Beanutils helps you writing this values into Java Objects.



回答3:

I have used both

  • jexcel
  • poi

And found jexcel is better. jexcel will provide you some fine control over reading/writing to excel which is not available through poi.



回答4:

If you don't want to write your own solution, or you need to load more comlicated data than a simple table, you may want to use Data tables from OpenL Tablets from [http://openl-tablets.sourceforge.net/][1] . It is based on Apache POI and works with both .xls and .xlsx files.



回答5:

I found these libraries that do what you ask:

  • Chicken Excel
  • Excel Pojo
  • Excel2Objects


回答6:

We make use of Poiji to map excel rows to Java objects