HSSFCellStyle.ALIGN_CENTER HSSFCellStyle.VERTICAL_CENTER 等爆红的解决办法

Apache POI是画excel工具,大家在接收旧代码时会出现以下问题:

HSSFCellStyle.ALIGN_CENTER HSSFCellStyle.VERTICAL_CENTER 等爆红

原因是版本出错:

        
            org.apache.poi</groupId>
            poi-ooxml</artifactId>
            4.1.2</version>
        </dependency>

以下是3.6及以下的版本显示:

		cellStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
		cellStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
		cellStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN);
		cellStyle.setBottomBorderColor(HSSFColor.BLACK.index);
		cellStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN);
		cellStyle.setLeftBorderColor(HSSFColor.BLACK.index);
		cellStyle.setBorderRight(HSSFCellStyle.BORDER_THIN);

更高版本是这样的:

        cellStyle.setAlignment(HorizontalAlignment.CENTER);
		cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
		cellStyle.setBorderBottom(BorderStyle.THIN);
		cellStyle.setBottomBorderColor(HSSFColor.HSSFColorPredefined.BLACK.getIndex());
		cellStyle.setBorderLeft(BorderStyle.THIN);
		cellStyle.setLeftBorderColor(HSSFColor.HSSFColorPredefined.BLACK.getIndex());
		cellStyle.setBorderRight(BorderStyle.THIN);
		cellStyle.setRightBorderColor(HSSFColor.HSSFColorPredefined.BLACK.getIndex());
		cellStyle.setBorderTop(BorderStyle.THIN);
		cellStyle.setTopBorderColor(HSSFColor.HSSFColorPredefined.BLACK.getIndex());

大家一一对应替换就可以啦

你可能感兴趣的:(错误,java)