0

Ahoi there,

I am trying to set the CellType of an XSSFCell. Basically I want to have just on set of methods to export a HSSF and a XSSFWorkbook and according to the API it SHOULD work.

   Workbook workbook = new XSSFWorkbook(); //Alternatively HSSFWorkbook
   Sheet sheet = workbook.createSheet();
        Row headerRow = sheet.createRow(0);
        for (int x = 0; x < exportColumns.size(); x++) {
            Cell createCell = headerRow.createCell(x);
            //Exception
            createCell.setCellType(CellType.STRING);
            //
            createCell.setCellValue(exportColumns.get(x));
        }

But I get the following NetBeans runtime hint when using an XSSFWorkbook (HSSF works fine):

createCell.setCellType(CellType.STRING) = >None of the "setCellType" methods in class "org.apache.poi.xssf.usermodel.XSSFCell" takes parameters of types "(org.apache.poi.ss.usermodel.CellType)".<

Problem is, that in the official API Doc the exactly some method shows up and I am using the latest Version. (April '17) https://poi.apache.org/apidocs/org/apache/poi/xssf/usermodel/XSSFCell.html#setCellType(org.apache.poi.ss.usermodel.CellType)

Anyone has some ideas to this? I dont want to have totally redundant code, just because I have to duplicate everything because of the CellTypes...

Update:

Version 3.1.6 from https://mvnrepository.com/artifact/org.apache.poi/poi.

Basically that is a runtime NetBeans Hint. The actual Exception is:

 Caused by: java.lang.AbstractMethodError: org.apache.poi.xssf.usermodel.XSSFCell.setCellType(Lorg/apache/poi/ss/usermodel/CellType;)V
    at de.htwk.leipzig.maxsolutions.service.ExportService.exportToExcel(ExportService.java:134)
    at de.htwk.leipzig.maxsolutions.service.ExportService.exportFile(ExportService.java:91)
    at de.htwk.leipzig.maxsolutions.controller.ExcelExportViewController.startExport(ExcelExportViewController.java:185)
    at de.htwk.leipzig.maxsolutions.controller.ExcelExportViewController.handleSaveAction(ExcelExportViewController.java:105)
    ... 58 more
Richard
  • 1
  • 2
  • 1
    Which POI version do you use? Also, I'm confused: you tell that the problem you face is an exception (which means that your code compiles well), but the 'Non of the ... methods ... takes parameters of types' looks like a compile-time error (although I never saw such errors). Could you please confirm that this is a runtime error? If yes, please post the stacktrace. – Roman Puchkovskiy Jun 10 '17 at 19:48
  • Version 3.1.6 and yes it is. – Richard Jun 10 '17 at 21:30
  • 2
    Cannot reproduce this. But two hints: 1. Explicitly setting of cell type is not necessary because the `setCellValue` methods will also set the cell type according to the type of the value. 2. `java.lang.AbstractMethodError` can only occur if a method is abstract at runtime while the same method at compile time was not abstract. Conclusion: The `apache poi` versions you are using at compile time are different from those at runtime. – Axel Richter Jun 11 '17 at 06:25
  • Thanks dude, somehow I totally oversaw for hours, that for some reasons I used the 3.10 version of poi-ooxml. Got the 3.16 version and now everything is running like intended. – Richard Jun 11 '17 at 08:50

0 Answers0