错误'java.lang.IllegalArgumentException'使用jxl时格式无效格式错误

时间:2017-12-20 14:47:13

标签: java netbeans jxl jexcelapi

您好我正在尝试使用jxl从excel文件中读取日期值,我对其他值没有问题,但是日期显示的错误显示

  

java.lang.IllegalArgumentException:格式无效:“342 / Dec / 17”是   在“/ Dec / 17”时感到格格不入,我错过了什么吗?

public static Object[][] readRegisters(String file) throws IOException, BiffException {

          ArrayList<Object[]> response = new ArrayList();
        Workbook workbook = Workbook.getWorkbook(new File(file));
        String[] names = workbook.getSheetNames();
        int shSrv = -1;
        for (int i = 0; i < names.length; i++) {
            if (names[i].toLowerCase().equals("registers")) {
                shSrv = i;
                break;
            }
        }
        if (shSrv < 0) {
            errores.error("file doesn't contain a sheet called registers");
            return new Object[0][0];
        }
        Sheet sheet = workbook.getSheet(shSrv);

        Cell[] row = sheet.getRow(0);

        int idsrv = -1;
        int sup = -1;
        int ver = -1;
        int pag = -1;

        for (int i = 0; i < row.length; i++) {
            Cell cell = row[i];
            if (cell.getContents().equals("ID")) {
                idsrv = i;
            }
            if (cell.getContents().equals("DATE")) {
                sup = i;
            }           
            if (cell.getContents().equals("MONEY")) {
                pag = i;
            }

        }
        if ((idsrv < 0) || (sup < 0) || (pag < 0) ) {
            errores.error("columns name error");
            return new Object[0][0];
        }     

//THIS IS WHERE I READ THE DATE > DateTime.parse((row[sup].getContents()))
        for (int i = 1; i < sheet.getRows(); i++) {
            row = sheet.getRow(i);            
            response.add(new Object[]{DateTime.parse(row[sup].getContents()),Integer.parseInt(row[idsrv].getContents()), Integer.parseInt(row[pag].getContents()) > 0 });

        }

        Object[][] table = createBiArrayFromArrayList(response);
        return table;

    }

1 个答案:

答案 0 :(得分:0)

解决它(有点),&#39;解决方案&#39;是将excel文件中列的格式从日期更改为字符串