Skip to content

Instantly share code, notes, and snippets.

@firegloves
Created July 11, 2019 15:23
Show Gist options
  • Save firegloves/d1ecb9a64caa70134975175ff981ab89 to your computer and use it in GitHub Desktop.
Save firegloves/d1ecb9a64caa70134975175ff981ab89 to your computer and use it in GitHub Desktop.
MemPOI - Overriding bundled template style
try {
// creates destination file
File file = new File("test.xlsx");
// creates date cells custom style settings
CellStyle dateCellStyle = workbook.createCellStyle();
dateCellStyle.setFillForegroundColor(IndexedColors.AQUA.getIndex());
dateCellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
dateCellStyle.setDataFormat(workbook.getCreationHelper().createDataFormat().getFormat("yyyy/MM/dd"));
// creates MemPOI using its builder and requests the export
MempoiBuilder.aMemPOI()
.withWorkbook(workbook)
.withFile(file)
.addMempoiSheet(new MempoiSheet(prepStmt))
.withStyleTemplate(new AquaStyleTemplate())
.withNumberCellStyle(workbook.createCellStyle()) // to remove default style you can just override it with a new empty one
.withDateCellStyle(dateCellStyle) // override default date cell style with the new one
.build()
.prepareMempoiReportToFile()
.get();
} catch (ExecutionException e) {
System.out.println(e.getCause().getMessage());
} catch (InterruptedException e) {
e.printStackTrace();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment