Skip to content
This repository has been archived by the owner on Nov 18, 2022. It is now read-only.
/ javaxcel-styler Public archive

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

License

Notifications You must be signed in to change notification settings

javaxcel/javaxcel-styler

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

65 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.