This is utility used for parsing excel sheets data into java object used for Inventory Management System here
Jackson for json format to java format maven link .
Apache Poi for .xlsx ( 2007 and above excel formats ) maven link and for .xls support you need to add maven link .
It can used for both .xls and .xslx file format together using this .
-
- Call parseFile method of FileParser which takes excel File and json format file of how the data will be mapped in POJO
File excelFile =new File('Absolute PATH of excel file'); File JSONFormatFile =new File('Absolute PATH of JSON format file'); FileParser<Inventory> fileParser = new FileParser<>(excelFile , JSONFormatFile ) ; Map<Class < ? extends Inventory > ,List<Inventory >> map = fileParser.parseFile();
-
It returns Map< Class<? extends T> , list<? extends T> > of POJO's
- Key for the Map is the Class of the POJO .
- Value is List of all the POJO's that are read from row of corresponding sheets
Note
T in my case is Inventory class which is common abstract class for all my POJO's .
-
Make sure that name of SheetFormat's name and POJO Class Name , the ColumnFormat's name and POJO's Fields name matches exactly , else SheetParsingException and RowParsingException is raised respectively .
-
Excel Sheets can be read from any index ( 0 based ) just provide index of the Sheet in JSONFormatFile like this
MIT