引入pom文件
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.17</version>
</dependency>
文件解析
public List<String[]> readExcel(MultipartFile excelInput, int startrow, int sheetnum) {
Workbook workbook = null;
InputStream inputStream = null;
List<String[]> list = new ArrayList<String[]>();
try {
inputStream = excelInput.getInputStream();
workbook = WorkbookFactory.create(inputStream);
//当使用路径时使用 Workbook wb = WorkbookFactory.create(new File(path));
int numberOfSheets = workbook.getNumberOfSheets();//sheet表
if (numberOfSheets >= sheetnum) {
Sheet sheet = workbook.getSheetAt(sheetnum);
if (null != sheet) {
// 获得当前sheet的开始行
//int firstRowNum = sheet.getFirstRowNum();
// 获得当前sheet的结束行
int lastRowNum = sheet.getLastRowNum();
for (int rowNum = startrow; rowNum <= lastRowNum; rowNum++) {
// 获得当前行
Row row = sheet.getRow(rowNum);
if (row == null) {
continue;
}
// 获得当前行的开始列
// int firstCellNum = row.getFirstCellNum();
// 获得当前行的列数