我使用Apache 3.15。我最近切换到最新的版本,我们现在有一些不推荐的方法‘短’边框样式,‘短’对齐.对于这些不推荐的方法,我们有带有Enum参数的新方法(比如BorderStyle、HorizontalAlignment、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短使用率
我在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样式为合并区域创建边界的解决方案吗?
发布于 2016-09-30 12:15:49
您需要使用比3.15更新的Apache版本,这在r1762856中是固定的
您需要ApachePOI3.16beta 1或更高版本,或者现在需要在20160930之后进行夜间/ svn主干/ git头构建。
https://stackoverflow.com/questions/39765675
复制相似问题