0

刚刚安装了 POI 3.8 jar 并更改了代码...我收到此错误:

 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;
    }
}

不能从静态上下文引用非静态方法 getFormat(java.lang.String)

4

2 回答 2

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.

于 2012-09-10T19:20:00.267 回答
0

DataFormat是一个接口,因此您不能在其上调用方法,就好像它们是静态的一样

您的代码应该类似于

   // 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");
   }
于 2012-09-10T20:40:43.123 回答