/javaxcel-styler

🎨 Configurer for decoration of cell style with simple usage. This is migrated to https://github.com/javaxcel/javaxcel

Primary LanguageJavaApache License 2.0Apache-2.0

This is migrated to https://github.com/javaxcel/javaxcel.


Javaxcel Styler

Javaxcel Styler

Configurer for decoration of cell style with simple usage

Maven Central jdk8
Lgtm grade Codacy grade

Getting started

Maven

<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>

Gradle

implementation group: "com.github.javaxcel", name: "javaxcel-styler", version: "$javaxcelStylerVersion"

// Required dependency
implementation group: "org.apache.poi", name: "poi-ooxml", version: "$apachePoiVersion"



Examples

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.