Apache POI 3.15: RegionUtil and BorderStyle?

I am using Apache POI 3.15. I recently switched to the latest version, and now we have some obsolete methods with “short” border styles, “short” alignment ... For these obsolete methods, we have new methods with the Enum parameter (for example, BorderStyle, HorizontalAlignment, FillPatternType ...). It's good for me.

Now I also use RegionUtil to put some styles for the merged regions. But RegionUtil seems to be using the old "short" style.

Here is my code (inspired by https://stackoverflow.com/a/127807/ ... , 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 several lines in my log, for example:

Limited use of BorderStyle

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

Enum?

+4
1

Apache POI, 3.15, r1762856

Apache POI 3.16 beta 1 , nightly/svn trunk/ git, 20160930

+3

Source: https://habr.com/ru/post/1656191/


All Articles