gpt4 book ai didi

java - Apache 兴趣点 3.15 : RegionUtil and BorderStyle?

转载 作者:搜寻专家 更新时间:2023-11-01 02:59:32 24 4
gpt4 key购买 nike

我使用 Apache POI 3.15。我最近切换到最新版本,我们现在有一些已弃用的方法,它们具有“短”边框样式、“短”对齐...对于这些已弃用的方法,我们有带有 Enum 参数的新方法(如 BorderStyle、Horizo​​ntalAlignment、FillPatternType...)。这对我来说没问题。

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

这是我的代码(灵感来自 https://stackoverflow.com/a/23619827/502040 但没有使用弃用的方法):

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 short usage

我在类 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;
}

您是否有使用枚举样式为合并区域制作边框的解决方案?

最佳答案

您需要使用比 3.15 更新的 Apache POI 版本,这仅在 r1762856 中得到修复

您需要 Apache POI 3.16 beta 1 或更新版本,或者现在是 20160930 之后制作的 nightly/svn trunk/git head build

关于java - Apache 兴趣点 3.15 : RegionUtil and BorderStyle?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39765675/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com