4

I use Apache POI 3.15. I recently switch to lastest version and we have now some deprecated methods with 'short' border styles, 'short' alignment... For these deprecated methods, we have new methods with Enum parameter (like BorderStyle, HorizontalAlignment, FillPatternType...). That's ok for me.

Now, I also use RegionUtil to put some styles for merged regions. But RegionUtil seems use old 'short' style.

Here my code (inspired from https://stackoverflow.com/a/23619827/502040 but without using deprecated methods) :

protected static void addMergedRegion(Sheet sheet, int iRowMin, int iRowMax, int iColMin, int iColMax) {
    CellRangeAddress cellZone = new CellRangeAddress(iRowMin, iRowMax, iColMin, iColMax);
    sheet.addMergedRegion(cellZone);

    Cell cell = sheet.getRow(iRowMin).getCell(iColMin);
    if (cell != null) {
        RegionUtil.setBorderBottom(cell.getCellStyle().getBorderBottomEnum().getCode(), cellZone, sheet);
        RegionUtil.setBorderTop(cell.getCellStyle().getBorderTopEnum().getCode(), cellZone, sheet);
        RegionUtil.setBorderLeft(cell.getCellStyle().getBorderLeftEnum().getCode(), cellZone, sheet);
        RegionUtil.setBorderRight(cell.getCellStyle().getBorderRightEnum().getCode(), cellZone, sheet);

        RegionUtil.setBottomBorderColor(cell.getCellStyle().getBottomBorderColor(), cellZone, sheet);
        RegionUtil.setTopBorderColor(cell.getCellStyle().getTopBorderColor(), cellZone, sheet);
        RegionUtil.setLeftBorderColor(cell.getCellStyle().getLeftBorderColor(), cellZone, sheet);
        RegionUtil.setRightBorderColor(cell.getCellStyle().getRightBorderColor(), cellZone, sheet);
    }
}

But I found in my log some lines like :

BorderStyle short usage

I found origin of this line in class CellUtil :

private static BorderStyle getBorderStyle(Map<String, Object> properties, String name) {
    Object value = properties.get(name);
    BorderStyle border;
    if (value instanceof BorderStyle) {
        border = (BorderStyle) value;
    }
    // @deprecated 3.15 beta 2. getBorderStyle will only work on BorderStyle enums instead of codes in the future.
    else if (value instanceof Short) {
        if (log.check(POILogger.WARN)) {
            log.log(POILogger.WARN, "Deprecation warning: CellUtil properties map uses Short values for "
                    + name + ". Should use BorderStyle enums instead.");
        }
        System.out.println("BorderStyle short usage");
        short code = ((Short) value).shortValue();
        border = BorderStyle.valueOf(code);
    }
    else if (value == null) {
        border = BorderStyle.NONE;
    }
    else {
        throw new RuntimeException("Unexpected border style class. Must be BorderStyle or Short (deprecated).");
    }
    return border;
}

Have you a solution to make some border for your merged regions with using Enum styles ?

Community
  • 1
  • 1
Guillaume Camus
  • 153
  • 1
  • 3
  • 8

1 Answers1

3

You need to use a newer version of Apache POI than 3.15, this was only fixed in r1762856

You need Apache POI 3.16 beta 1 or newer, or for now a nightly / svn trunk / git head build made after 20160930

Gagravarr
  • 47,320
  • 10
  • 111
  • 156