怎么读取本地的一个Excel表格的数据存入数据库中-怎么读取本地的一个Excel表格的数据存入数据库中-怎么读取本地的一个Excel表格的数据存入数据库中

解决方案 »

  1.   

    下一个开源的jar包,有专门解析excel的
      

  2.   


    public String importEdittrainersultDetail() throws FileNotFoundException,
    IOException {
    String trainClassId = getRequest().getParameter("trainClassId");
    educationTrainClass = tEducationTrainClassService
    .fetchTEducationTrainClassByTrainClassId(trainClassId);
    HSSFWorkbook workbook = new HSSFWorkbook(new FileInputStream(
    getUploadFile()[0]));
    HSSFSheet sheet = workbook.getSheetAt(0);
    int rowNum = sheet.getLastRowNum();
    for (int j = 3; j <= rowNum; j++) {
    HSSFRow row = sheet.getRow(j);
    if (row == null) {
    continue;
    }
    HSSFCell cell1 = row.getCell((short) 0);
    HSSFCell cell2 = row.getCell((short) 1);
    HSSFCell cell3 = row.getCell((short) 2);
    HSSFCell cell4 = row.getCell((short) 3);
    HSSFCell cell5 = row.getCell((short) 4);
    HSSFCell cell6 = row.getCell((short) 5);
    HSSFCell cell7 = row.getCell((short) 6);
    HSSFCell cell8 = row.getCell((short) 7);
    HSSFCell cell9 = row.getCell((short) 8);
    HSSFCell cell10 = row.getCell((short) 9); TPoliceStudent tPoliceStudent = new TPoliceStudent();
    tPoliceStudent.setTEducationTrainClass(educationTrainClass);
    tPoliceStudent.setName(cell1.getRichStringCellValue().getString());
    tPoliceStudent.setPoliceNumber(cell2.getRichStringCellValue()
    .getString());
    tPoliceStudent.setSex(cell3.getRichStringCellValue().getString());
    tPoliceStudent.setDeptKsd(cell4.getRichStringCellValue()
    .getString());
    tPoliceStudent.setDuty(cell5.getRichStringCellValue().getString());
    tPoliceStudent.setPoliceType(cell6.getRichStringCellValue()
    .getString());
    tPoliceStudent.setPersonalEvaluation(cell7.getRichStringCellValue()
    .getString());
    tPoliceStudent.setPromoteInsignias(cell8.getRichStringCellValue()
    .getString());
    tPoliceStudent.setPromoteType(cell9.getRichStringCellValue()
    .getString());
    tPoliceStudent.setBirthday(DateUtils.parseDate(cell10
    .getRichStringCellValue().getString()));
    tPoliceStudentService.insertTPoliceStudent(tPoliceStudent);
    }
    return SUCCESS;
    }
    整个发上来自已改改吧