`
刘赛勋
  • 浏览: 8151 次
  • 性别: Icon_minigender_1
社区版块
存档分类
最新评论

excel导入

    博客分类:
  • Java
阅读更多
jsp  form协议要添加enctype="multipart/form-data"

protected Sheet getSheet(HttpServletRequest request) throws Exception {
request.setCharacterEncoding("UTF-8");
DiskFileItemFactory factory = new DiskFileItemFactory();
ServletFileUpload upload = new ServletFileUpload(factory);
List<FileItem> items = upload.parseRequest(request);
Iterator<FileItem> itr = items.iterator();
Sheet sheet = null;
while (itr.hasNext()) {
FileItem item = (FileItem) itr.next();
if (item.isFormField()) {
System.out.println("getFieldName" + item.getFieldName()
+ "UTF-8" + item.getString("UTF-8"));
} else {
System.out.println("getSize" + item.getSize());
System.out.println("getContentType" + item.getContentType());
System.out.println("getName" + item.getName());
Workbook workbook = WorkbookFactory.create(item
.getInputStream());
sheet = workbook.getSheetAt(0);

}
}
return sheet;

}
调用方法
public void batchUpload(HttpServletRequest request, HttpServletResponse response) throws Exception {
log.info("****   batchUpload***");
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
Learner learner=new Learner();


String pwd=multipartRequest.getParameter("pwd");
String fid=multipartRequest.getParameter("fid");
System.out.println("*************************pwd**********************************"+pwd+"**************************************************fid**********************************"+fid);

Sheet sheet = this.getSheet(request);
Iterator<Row> iterator=sheet.rowIterator();
while(iterator.hasNext()){
String id=CommonUtils.getUUID();
Row row=iterator.next();
String code=CommonUtils.getXlsValue(row.getCell(0));//工号code
String degree=CommonUtils.getXlsValue(row.getCell(1));//学位degree


this.learnerService.saveAndUpdate(learner);

}
this.alert(response, ExceptionMsg.UI_SUC, "/learner/list");
}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics