Marshalling and unmarshalling Excel Spreadsheets to Java Objects using annotations. It takes only 4 steps to start using it.
- Add maven dependency to your project.
<dependency>
<groupId>com.github.camaral</groupId>
<artifactId>sheeco</artifactId>
<version>1.0</version>
</dependency>
- Create a Excel spreadsheet.
name | Male? | Birth date | hairLength | hairColor | hairLength | hairColor |
---|---|---|---|---|---|---|
Floofly | false | 2014/12/12 | 1 | orange | 1 | yellow |
Tor | true | 2014/11/11 | 3 | black | 0 | grey |
- Describe the Excel spread sheet on Java classes.
@SpreadsheetPayload(name = "Cat")
public class Cat {
@SpreadsheetAttribute(index = 0)
String name;
@SpreadsheetAttribute(index = 1, name="Male?")
Boolean male;
@SpreadsheetAttribute(index = 2, name="Birth date")
Date birthDate;
@SpreadsheetElement(index = 3)
Fur body;
@SpreadsheetElement(index = 5)
Fur tail;
}
@SpreadsheetPayload(name = "Fur")
public class Fur {
@SpreadsheetAttribute(index = 0)
private Integer hairLength;
@SpreadsheetAttribute(index = 1)
private String hairColor;
}
- Read the spreadsheet from a File or from an InputStream.
List<Cat> cats = Sheeco.fromSpreadsheet(new File(cats.xls), Cat.class);