This is migrated to https://github.com/javaxcel/javaxcel.
Configurer for decoration of cell style with simple usage
<dependency>
<groupId>com.github.javaxcel</groupId>
<artifactId>javaxcel-styler</artifactId>
<version>${javaxcel-styler.version}</version>
</dependency>
<!-- Required dependency -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>${apache-poi.version}</version>
</dependency>
implementation group: "com.github.javaxcel", name: "javaxcel-styler", version: "$javaxcelStylerVersion"
// Required dependency
implementation group: "org.apache.poi", name: "poi-ooxml", version: "$apachePoiVersion"
public class DefaultHeaderStyleConfig implements ExcelStyleConfig {
@Override
public void configure(Configurer configurer) {
configurer
.alignment()
.horizontal(HorizontalAlignment.CENTER)
.vertical(VerticalAlignment.CENTER)
.and()
.background(FillPatternType.SOLID_FOREGROUND, IndexedColors.GREY_25_PERCENT)
.border()
.leftAndRight(BorderStyle.THIN, IndexedColors.BLACK)
.bottom(BorderStyle.MEDIUM, IndexedColors.BLACK)
.and()
.font()
.name("Arial")
.size(12)
.color(IndexedColors.BLACK)
.bold();
}
}
File file = new File("/data", "result.xlsx");
try (FileOutputStream out = new FileOutputStream(file);
Workbook workbook = new XSSFWorkbook()) {
Cell cell;
/* ... */
CellStyle headerStyle = workbook.createCellStyle();
Font font = workbook.createFont();
// Applies custom style configuration to cell style.
new DefaultHeaderStyleConfig().configure(new Configurer(headerStyle, font));
cell.setCellStyle(headerStyle);
/* ... */
workbook.write(out);
} catch (IOException e) {
e.printStackTrace();
}
You can configure custom style with implementation or lambda expression.
The implementation of ExcelStyleConfig
must have default constructor.