Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @JacksonXmlRootElement(localName = "kpi-accounts")
- @JsonRootName("kpi-accounts")
- @XlsxSheetProperty(name = "accounts")
- public class KPIAccountsTO extends KPIEntityTO {
- private static final long serialVersionUID = 1L;
- private int active;
- private int onBoardingPending;
- private int notActive;
- public KPIAccountsTO() {
- super();
- }
- // setters omitted for brevity ...
- @JacksonXmlProperty(localName = "active")
- @JsonProperty(value = "active", index = 0)
- @XlsxColumnProperty(name = "active", index = 0)
- public int getActive() {
- return active;
- }
- @JacksonXmlProperty(localName = "on-boarding-pending")
- @JsonProperty(value = "on-boarding-pending", index = 1)
- @XlsxColumnProperty(name = "on-boarding-pending", index = 1, widthModifier = 2)
- public int getOnBoardingPending() {
- return onBoardingPending;
- }
- @JacksonXmlProperty(localName = "not-active")
- @JsonProperty(value = "not-active", index = 2)
- @XlsxColumnProperty(name = "not-active", index = 2)
- public int getNotActive() {
- return notActive;
- }
- }
- public static XSSFSheet createDefaultSheet(XSSFWorkbook book, Class<?> clazzHeader) {
- XlsxSheetProperty sheetAnnotation = clazzHeader.getAnnotationsByType(XlsxSheetProperty.class)[0];
- XSSFSheet sheet = book.createSheet(sheetAnnotation.name().toUpperCase());
- ...
- createRowHeder(sheet, clazzHeader);
- return sheet;
- }
- private static XSSFRow createRowHeder(XSSFSheet sheet, Class<?> clazzHeader) {
- XSSFRow header = sheet.createRow(0);
- Method[] methods = Arrays.stream(clazzHeader.getMethods())
- .filter(method -> method.isAnnotationPresent(XlsxColumnProperty.class))
- // Sorted by index
- .sorted((m1, m2) -> Integer.compare(
- // m1
- m1.getAnnotation(XlsxColumnProperty.class).index(),
- // m2
- m2.getAnnotation(XlsxColumnProperty.class).index()))
- .toArray(size -> new Method[size]);
- //TODO: Move the stream pipeline
- for (int idx = 0; idx < methods.length; idx++) {
- XlsxColumnProperty annotation = methods[idx].getAnnotation(XlsxColumnProperty.class);
- createDefaultCell(idx, header).setCellValue(annotation.name().toUpperCase());
- sheet.setColumnWidth(idx, sheet.getColumnWidth(idx) * annotation.widthModifier());
- }
- return header;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement