Apache POI 3.X Upgrade to 4.X

Recently I upgraded Apache POI Library from 3.X to 4.X, there are some codes need to rewrite.

  1. HSSFCellStyle.ALIGN_CENTER -> HorizontalAlignment.CENTER
  2. HSSFCellStyle.VERTICAL_CENTER -> VerticalAlignment.CENTER
  3. BorderStyle.THIN , you could use the type’s name to define the border style. ex: MEDIUM, DASHED, DOTTED….
  4. font.setBoldweight(Font.BOLDWEIGHT_BOLD); -> font.setBold(true);
  5. HSSFColor.PALE_BLUE.index -> HSSFColorPredefined.PALE_BLUE.getIndex()
  6. style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
  7. CellType check , when you get the data from cell, you need to check the celltype then call different function by different type.

Notice : The POI 4.x is dependency on xmlbeams 3.1.1 , if you use the xmlbeams 2.6.0 , it would be something wrong, like “java.lang.NoSuchMethodError: org.apache.xmlbeans.XmlOptions.setEntityExpansionLimit(I)Lorg/apache/xmlbeans/XmlOptions;”.

Related Posts