使用的是poi3.17版本
public class ExcelUtils {
public static List<String> readXlsx(String path) throws IOException{
InputStream is = new FileInputStream(path);
Workbook excel = null;
String extString = path.substring(path.lastIndexOf("."));
//判断excel文件的版本
if(extString.equals(".xls")){
excel = new HSSFWorkbook(is);
}else if(extString.equals(".xlsx")){
excel = new XSSFWorkbook(is);
}
String str = null;
List<String> list = new ArrayList<String>();
// 循环工作表Sheet
for (int numSheet = 0; numSheet < excel.getNumberOfSheets(); numSheet++) {
Sheet sheet = excel.getSheetAt(numSheet);
if (sheet == null){
continue;
}
// 循环行Row
for (int rowNum = 1; rowNum <= sheet.getLastRowNum(); rowNum++) {
Row row = sheet.getRow(rowNum);
if (row == null){
continue;
}
// 循环列Cell
for(int cellNum = 0; cellNum < row.getLastCellNum(); cellNum++){
Cell cell = row.getCell(cellNum);
if(cell == null){
continue;
}
str = String.valueOf((int)cell.getNumericCellValue());
list.add(str);
}
}
}
return list;
}
}
poi3.17版本的xmlbeans,jar会和xbeans.jar冲突,将xbeans删除就可以了