Spring 3 controller Code Snippet to Read Data from the uploaded document :
@RequestMapping(value = "/processExcel", method = RequestMethod.POST)
public String processExcel(
@RequestParam("excelfile") MultipartFile excelfile) {
try {
int i = 0;
//Creates a workbook object from the uploaded excelfile
HSSFWorkbook workbook = new HSSFWorkbook(excelfile.getInputStream());
//Creates a worksheet object representing the first sheet
HSSFSheet worksheet = workbook.getSheetAt(0);
//Reads the data in excel file until last row is encountered
while (i < worksheet.getLastRowNum()) {
//Creates an object for the Candidate Model
Candidate candidate=new Candidate();
//Creates an object representing a single row in excel
HSSFRow row = worksheet.getRow(i++);
//Sets the Read data to the model class
candidate.setCandidateId((int)row.getCell(0).getNumericCellValue());
candidate.setName(row.getCell(1).getStringCellValue());
candidate.setAddress(row.getCell(2).getStringCellValue());
candidate.setEmailId(row.getCell(3).getStringCellValue());
candidate.setPinCode((int)row.getCell(4).getNumericCellValue());
candidate.setAboutCandidate(row.getCell(5).getStringCellValue());
//Sends the model object to service layer for validation,
//data processing and then to persist
iCandidateService.saveCandidate(candidate);
}
} catch (Exception e) {
e.printStackTrace();
}
return "uploadSuccess";
}
<dependency> <groupId>org.apache.poi</groupId> <artifactId>poi</artifactId> <version>3.7</version> </dependency>


February 25, 2013 at 1:46 AM
not working this code except xlsx format