首页 > 编程语言 > 详细

Java导入excel

时间:2019-08-08 15:59:18      阅读:92      评论:0      收藏:0      [点我收藏+]
需要先倒入POI的jar
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.8</version>
</dependency>


public String exportCharge(MultipartHttpServletRequest request) {
try {
//得到上传的文件
MultipartFile fileFile = request.getFile("file");
//转换成输入流
InputStream in = fileFile.getInputStream();
XSSFWorkbook readWb = new XSSFWorkbook(in);
//遍历该表格中所有的工作表,i表示工作表的数量 getNumberOfSheets表示工作表的总数

XSSFSheet sheet = readWb.getSheetAt(0);
//循环行Row
for (int rowNum = 1; rowNum <= sheet.getLastRowNum(); rowNum++) {
System.out.println("当前插入第"+rowNum);
XSSFRow hssfRow = sheet.getRow(rowNum);
AllPhone allPhone=new AllPhone();
if (hssfRow != null) {
for (int colNum = 0; colNum < hssfRow.getPhysicalNumberOfCells(); colNum++) {
String tmp = hssfRow.getCell(colNum).toString();
if (colNum == 0) {
int begin = tmp.indexOf(".");
} else if (colNum == 1) {
allPhone.setStage(tmp);
}else if (colNum == 2) {

}else if (colNum == 3) {
allPhone.setCardtype(tmp);
}else if (colNum == 4) {


}else if (colNum == 5) {
if(StringUtil.isNotEmpty(tmp)){
allPhone.setPostcode(tmp);
}
}
}
}
}

} catch (Exception e) {
e.printStackTrace();
}
return "ok";
}


Java导入excel

原文:https://www.cnblogs.com/foreverstudy/p/11321234.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!