赞
踩
1、添加pom依赖文件
<dependency>
<groupId>net.sourceforge.jexcelapi</groupId>
<artifactId>jxl</artifactId>
<version>2.6</version>
</dependency>
2、循环读取excel行
private static List<String> parseExcelChargePos(File file) throws Exception{
List<String> list = new ArrayList<>();
Workbook wb = Workbook.getWorkbook(file);
Sheet sheet = wb.getSheets()[0];
for (int i = 1; i <=sheet.getRows(); i++) {
Cell cell = sheet.getCell(0, i);
String content = cell.getContents();
list.add(content);
}
return list;
}
3、测试方法
List<String> userPos = parseExcelChargePos(new File("/27000099.xls"));
for (String user:userPos) {
logger.info("正在插入数据:"+i);
//业务处理代码
}
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。