目录
报错2:HSSFColor.GREY_25_PERCENT.index
报错3:HSSFCellStyle.SOLID_FOREGROUND
报错6:HSSFCellStyle.ALIGN_CENTER
报错7: POIOLE2TextExtractor 、PowerPointExtractor、XSLFPowerPointExtractor
报错8: setRepeatingRowsAndColumns
前言
升级poi依赖问题记录,由于产品需要升级poi版本,导致很多报错需要改!
报错1:HSSFCellStyle.BORDER_THIN
//cellStyle.setBorderTop(HSSFCellStyle.BORDER_THIN);
//cellStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN);
//cellStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN);
//cellStyle.setBorderRight(HSSFCellStyle.BORDER_THIN);
cellStyle.setBorderTop(BorderStyle.THIN);
cellStyle.setBorderBottom(BorderStyle.THIN);
cellStyle.setBorderLeft(BorderStyle.THIN);
cellStyle.setBorderRight(BorderStyle.THIN);
解决办法:替换为 BorderStyle.THIN 即可
报错2:HSSFColor.GREY_25_PERCENT.index
//cellStyle.setFillBackgroundColor(HSSFColor.GREY_25_PERCENT.index);
//cellStyle.setFillForegroundColor(HSSFColor.GREY_25_PERCENT.index);
cellStyle.setFillBackgroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
cellStyle.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
解决办法: 替换为 IndexedColors.GREY_25_PERCENT.getIndex() 即可
报错3:HSSFCellStyle.SOLID_FOREGROUND
//cellStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
cellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
解决办法:替换为 FillPatternType.SOLID_FOREGROUND 即可
报错4: HSSFFont.BOLDWEIGHT_BOLD
//font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
font.setBold(true);
解决办法:换成 setBold() 方法
报错5:XSSFCell.CELL_TYPE_STRING
//createCell(wb, row, column, value, XSSFCell.CELL_TYPE_STRING);
//createCell(wb, row, column, value, XSSFCell.CELL_TYPE_NUMERIC);
//createCell(wb, row, column, value, XSSFCell.CELL_TYPE_BOOLEAN);
//createCell(wb, row, column, value, XSSFCell.CELL_TYPE_FORMULA);
//createCell(wb, row, column, value, XSSFCell.CELL_TYPE_ERROR);
createCell(wb, row, column, value, CellType.STRING);
createCell(wb, row, column, value, CellType.NUMERIC);
createCell(wb, row, column, value, CellType.BOOLEAN);
createCell(wb, row, column, value, CellType.FORMULA);
createCell(wb, row, column, value, CellType.ERROR);
解决办法:换成 CellType.STRING
报错6:HSSFCellStyle.ALIGN_CENTER
//cellStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);//水平
//cellStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);//垂直
cellStyle.setAlignment(HorizontalAlignment.CENTER);//水平
cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);//垂直
解决办法:换成 HorizontalAlignment.CENTER
报错7: POIOLE2TextExtractor 、PowerPointExtractor、XSLFPowerPointExtractor
//POIOLE2TextExtractor oleTextExtractor = ExtractorFactory.createExtractor(fileSystem);
POITextExtractor oleTextExtractor = ExtractorFactory.createExtractor(fileSystem);
//PowerPointExtractor powerPointExtractor = (PowerPointExtractor) oleTextExtractor;
SlideShowExtractor powerPointExtractor = (SlideShowExtractor) oleTextExtractor;
//XSLFPowerPointExtractor extractor = new XSLFPowerPointExtractor(OPCPackage.open(fis));
SlideShowExtractor extractor = new SlideShowExtractor((SlideShow)fis);
解决办法:POIOLE2TextExtractor换成POITextExtractor
PowerPointExtractor、XSLFPowerPointExtractor换成SlideShowExtractor
报错8: setRepeatingRowsAndColumns
HSSFSheet sheet = wb.createSheet("new sheet");
// sheet.setRepeatingRowsAndColumns(0, -1, -1, 0, 0);
sheet.setRepeatingRows(new CellRangeAddress(-1, -1, 0, 0));
解决办法:setRepeatingRowsAndColumns换成setRepeatingRows写法
参考:NPOI导出EXCEL 打印设置分页及打印标题 - 走看看
报错9: new XSSFWorkbook();
java.lang.NoClassDefFoundError: org/apache/commons/io/output/UnsynchronizedByteArrayOutputStream
解决办法:commons-io升级为commons-io2.11.0
改了还是报错:
java.lang.ClassNotFoundException: org.apache.commons.collections4.ListValuedMap
解决办法:
如果commons-collections直接升级为commons-collections4-4.1,升级之后FastHashMap会报错,由于这两个版本不冲突,可以共存,那就直接collections和collections4共存
参考:https://blog.51cto.com/u_15127675/4530581
还有各种报红:beanutils是依赖logging的
解决:collection升级之后commons-beanutils升级为commons-beanutils-1.8.3、commons-logging也要升级为commons-logging-1.1.1
改了之后又报错!
java.lang.NoSuchMethodError: org.apache.xmlbeans.XmlOptions.setUseDefaultNamespace(Z)Lorg/apache/xmlbeans/XmlOptions;
解决办法: 升级xml-beans为xml-beans3.1.0
然后就没有报错了,解决麻烦了!
参考博客:poi从3.6 升级为新版本5.2.2,导致 原先的代码 报错,替换方案_耷腊呜呜的博客-CSDN博客_cellstyle.border_thin报错