首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ApachePOI3.15: RegionUtil和BorderStyle?

ApachePOI3.15: RegionUtil和BorderStyle?
EN

Stack Overflow用户
提问于 2016-09-29 08:52:07
回答 1查看 5.1K关注 0票数 4

我使用Apache 3.15。我最近切换到最新的版本,我们现在有一些不推荐的方法‘短’边框样式,‘短’对齐.对于这些不推荐的方法,我们有带有Enum参数的新方法(比如BorderStyle、HorizontalAlignment、FillPatternType.)。对我来说没问题。

现在,我还使用RegionUtil为合并区域放置一些样式。但RegionUtil似乎采用了旧的“短”风格。

在这里,我的代码(灵感来自https://stackoverflow.com/a/23619827/502040,但不使用不推荐的方法):

代码语言:javascript
复制
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);
    }
}

但我在我的日志里发现了这样的几行:

BorderStyle短使用率

我在CellUtil类中找到了这一行的起源:

代码语言:javascript
复制
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样式为合并区域创建边界的解决方案吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-09-30 12:15:49

您需要使用比3.15更新的Apache版本,这在r1762856中是固定的

您需要ApachePOI3.16beta 1或更高版本,或者现在需要在20160930之后进行夜间/ svn主干/ git头构建。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39765675

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档