我使用的是Apache POI 3.15.
我最近切换到最新版本,我们现在有一些不赞成的方法,有’短’边框样式,’短’对齐…
对于这些已弃用的方法,我们有使用Enum参数的新方法(如BorderStyle,HorizontalAlignment,FillPatternType …).
没关系对我来说.
现在,我还使用RegionUtil为合并区域添加一些样式.
但RegionUtil似乎使用旧的“短”风格.
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 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样式为合并区域制作边框的解决方案?