POI:上传EXCEL解析
来源:互联网 发布:怎么做好淘宝店铺 编辑:程序博客网 时间:2024/05/29 05:53
public String upload()throws Exception{
POIFSFileSystem fs=new POIFSFileSystem(new FileInputStream(userUploadFile));//根据流来创建workbook
HSSFWorkbook wb=new HSSFWorkbook(fs);
HSSFSheet hssfSheet=wb.getSheetAt(0); // 获取第一个Sheet页
if(hssfSheet!=null){
for(int rowNum=1;rowNum<=hssfSheet.getLastRowNum();rowNum++){
HSSFRow hssfRow=hssfSheet.getRow(rowNum);
if(hssfRow==null){
continue;
}
User user=new User();
user.setName(ExcelUtil.formatCell(hssfRow.getCell(0)));
user.setPhone(ExcelUtil.formatCell(hssfRow.getCell(1)));
user.setEmail(ExcelUtil.formatCell(hssfRow.getCell(2)));
user.setQq(ExcelUtil.formatCell(hssfRow.getCell(3)));
Connection con=null;
try{
con=dbUtil.getCon();
userDao.userAdd(con, user);
}catch(Exception e){
e.printStackTrace();
}finally{
dbUtil.closeCon(con);
}
}
}
POIFSFileSystem fs=new POIFSFileSystem(new FileInputStream(userUploadFile));//根据流来创建workbook
HSSFWorkbook wb=new HSSFWorkbook(fs);
HSSFSheet hssfSheet=wb.getSheetAt(0); // 获取第一个Sheet页
if(hssfSheet!=null){
for(int rowNum=1;rowNum<=hssfSheet.getLastRowNum();rowNum++){
HSSFRow hssfRow=hssfSheet.getRow(rowNum);
if(hssfRow==null){
continue;
}
User user=new User();
user.setName(ExcelUtil.formatCell(hssfRow.getCell(0)));
user.setPhone(ExcelUtil.formatCell(hssfRow.getCell(1)));
user.setEmail(ExcelUtil.formatCell(hssfRow.getCell(2)));
user.setQq(ExcelUtil.formatCell(hssfRow.getCell(3)));
Connection con=null;
try{
con=dbUtil.getCon();
userDao.userAdd(con, user);
}catch(Exception e){
e.printStackTrace();
}finally{
dbUtil.closeCon(con);
}
}
}
}
public static String formatCell(HSSFCell hssfCell){
if(hssfCell==null){
return "";
}else{
if(hssfCell.getCellType()==HSSFCell.CELL_TYPE_BOOLEAN){
return String.valueOf(hssfCell.getBooleanCellValue());
}else if(hssfCell.getCellType()==HSSFCell.CELL_TYPE_NUMERIC){
return String.valueOf(hssfCell.getNumericCellValue());
}else{
return String.valueOf(hssfCell.getStringCellValue());
}
}
}
0 0
- POI:上传EXCEL解析
- java 利用POI 上传解析导出Excel 深入
- ocupload、struts2实现excel文件上传,poi解析
- 用POI上传EXCEL表格 日期解析问题
- poi上传excel
- SpringMvc+POI上传Excel
- poi上传excel
- poi上传excel
- POI解析Excel
- POI 解析Excel
- 使用poi解析Excel
- 使用poi解析Excel
- 使用poi解析Excel
- 使用poi解析Excel
- java poi 解析excel
- POI解析Excel
- 《POI解析复杂Excel》
- poi 解析excel
- 异常
- Java工程师成神之路
- 一个Mathematica能解Maple不行的特殊积分
- List中的Contains
- RecyclerView的长按多选功能
- POI:上传EXCEL解析
- 面向对象--接口的实际应用
- nodejs入门二
- remoting与socket、web service的比较及实例
- hive的几个疑问点
- 包的基本概念
- thinkphp图片集合
- 处理 windows server 2008 r2 每隔一段时间自动关机笔记
- 四个代码块