<dependencies>
<dependency>
<groupId>com.yo1000</groupId>
<artifactId>fishbone</artifactId>
<version>1.0.2</version>
</dependency>
</dependencies>
public static void main(String[] args) {
Sales sales = new Sales(
"Flower shop",
new Date(),
new ArrayList<SalesStatement>() {
{
add(new SalesStatement("Clover", 450, 1));
add(new SalesStatement("Moss phlox", 200, 2));
add(new SalesStatement("Rosemary", 270, 1));
}
});
new XlsxSheetMapper().map(
Application.class.getResourceAsStream("/template.xlsx"),
sales,
false,
new Function1<Workbook, Unit>() {
@Override
public Unit invoke(Workbook workbook) {
try {
workbook.write(new FileOutputStream(new File(
"target/template1.wrote.xlsx")));
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
}
);
}
public static class SalesStatement {
private String name;
private int price;
private int number;
public SalesStatement(String name, int price, int number) {
this.name = name;
this.price = price;
this.number = number;
}
// Getter/Setter
public int getSubtotal() {
return getPrice() * getNumber();
}
}
public static class Sales {
private String subject;
private Date date;
private List<SalesStatement> items;
public Sales(String subject, Date date, List<SalesStatement> items) {
this.subject = subject;
this.date = date;
this.items = items;
}
// Getter/Setter
public int getTotalNumber() {
int total = 0;
for (SalesStatement statement : getItems()) {
total += statement.getNumber();
}
return total;
}
public int getTotalFee() {
int total = 0;
for (SalesStatement statement : getItems()) {
total += statement.getSubtotal();
}
return total;
}
}