如何在Play Framework Java中将文件Excel数据上传到数据库

时间:2018-08-16 04:20:26

标签: java playframework apache-poi

我也尝试下面的代码,但是显示错误HSSFWorkbook,poi,HSSFRowHSSFCell和ExcelFile

  public Result readExcel() throws FileNotFoundException {
        try{
            InputStream ExcelFileToRead = new FileInputStream("/home/jagasan/workspace-play/excelApp/public/ExcelFile3.xlsx");

        HSSFWorkbook wb = new HSSFWorkbook(ExcelFileToRead);
        HSSFSheet sheet=wb.getSheetAt(0);
        HSSFRow row;
        HSSFCell cell;
        Iterator rows = sheet.rowIterator();
        boolean flag=false;
        while (rows.hasNext())
        {
            row=(HSSFRow) rows.next();
            if(flag==false)
            {
                flag=true;
                continue;
            }
            Iterator cells = row.cellIterator();
            ExcelFile excelfile=new ExcelFile();
            int i=0;
            while (cells.hasNext())
            {
                cell=(HSSFCell) cells.next();
                if(i==0)
                    excelfile.setEmpNo((int)cell.getNumericCellValue());
                if(i==1)
                    excelfile.setName(cell.getStringCellValue());
                if(i==2)
                    excelfile.setSalary(cell.getNumericCellValue());
                i++;

            }
            excelfile.save();

        }
    }
    catch(Exception e)
    {
        e.printStackTrace();
        System.out.println("error");
    }
    return ok("successful");
}

0 个答案:

没有答案