我也尝试下面的代码,但是显示错误HSSFWorkbook
,poi,HSSFRow
,HSSFCell
和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");
}