Skip to content

Column configuration

firegloves edited this page Jul 20, 2022 · 1 revision

Column Configuration

MemPOI 1.5 introduces the concept of column configuration, allowing the user to add some column specific configurations. The binding is made throughout column name and currently 2 configuration are supported: column cell style and data transformation functions

Here is a basic example to create an empty column configuration for the column "name":

MempoiColumnConfig mempoiColumnConfig = MempoiColumnConfigBuilder.aMempoiColumnConfig()
        .withColumnName("name")
        .build();

MempoiSheet mempoiSheet = MempoiSheetBuilder.aMempoiSheet()
        .withPrepStmt(prepStmt)
        .addMempoiColumnConfig(mempoiColumnConfig)
        .build();

As you can see, you add your desired MempoiColumnConfigs to the MempoiSheet, then MemPOI at runtime will search for the column identified by the name supplied and apply to it the desired customizations.

Column cell style

Up to v1.4 MemPOI applies cell styles basing on data type, from v1.5 you can supply custom cell styles that will be applied to particular columns. Look at the following example:

CellStyle nameColumnCellStyle = workbook.createCellStyle();
        nameColumnCellStyle.setFillForegroundColor(IndexedColors.AQUA.getIndex());
        nameColumnCellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);

MempoiColumnConfig mempoiColumnConfig = MempoiColumnConfigBuilder.aMempoiColumnConfig()
        .withColumnName(MempoiColumnConfigTestHelper.COLUMN_NAME)
        .withCellStyle(nameColumnCellStyle)
        .build();

This will result in having the entire "name" column with an aqua background.