0

Just installed POI 3.8 jars and changing over code...I get this error:

 public static void setStyleDataFormat( CellStyle style, int formatType )
{
    switch( formatType )
    {
        case CELL_TYPE_PERCENTAGE:

            style.setDataFormat(DataFormat.getFormat("0%"));
            break;

        case CELL_TYPE_PERCENTAGE_TWO_DECIMAL_PLACES:

            style.setDataFormat(DataFormat.getFormat("0.00%"));
            break;

        case CELL_TYPE_NUMERIC:

            style.setDataFormat(DataFormat.getFormat("#,##0"));
            break;

        case CELL_TYPE_NUMERIC_TWO_DECIMAL_PLACES:

            style.setDataFormat(DataFormat.getFormat("#,##0.00"));
            break;

        case CELL_TYPE_DATE:
        case CELL_TYPE_DATE_EMPTY_ON_ERROR:

            style.setDataFormat(DataFormat.getFormat("m/d/yy"));
            break;

        case CELL_TYPE_CURRENCY:

            style.setDataFormat(DataFormat.getFormat("($#,##0.00);($#,##0.00)"));
            break;

        case CELL_TYPE_CURRENCY_NO_CENTS:

            style.setDataFormat(DataFormat.getFormat("($#,##0_);($#,##0)"));
            break;
    }
}

non-static method getFormat(java.lang.String) cannot be referenced from a static context

Doc Holiday
  • 9,928
  • 32
  • 98
  • 151

2 Answers2

1

non static method cannot be referenced from static context should be able to help you fix this. It seems that Apache decided you shouldn't be so static.

reevesy
  • 3,452
  • 1
  • 26
  • 23
Shaded
  • 17,276
  • 8
  • 37
  • 62
0

DataFormat is an interface, so you can't call methods on it as if they were static

Your code should instead be something like

   // Do this once per workbook
   DataFormat format = wb.createDataFormat();

   .....

   // Use the object in your per-cell work
   for (Cell c : row) {
       CellStyle cs = c.getCellStyle();
       cs.setDataFormat(format.get("dd/mm/yyyy");
   }
Gagravarr
  • 47,320
  • 10
  • 111
  • 156