|
|
|
@ -387,6 +387,7 @@ public class ExcelKit {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 读取excel文件
|
|
|
|
|
*
|
|
|
|
|
* @param excelFilePath
|
|
|
|
|
* @param skipRows
|
|
|
|
|
* @return
|
|
|
|
@ -482,10 +483,82 @@ public class ExcelKit {
|
|
|
|
|
data = ExcelKit.readExcelToList(ExcelKit.excelPath, skipRows);
|
|
|
|
|
System.out.println("二次获取数据条目数量:" + data.size() + ",期望数量=" + expectLimit);
|
|
|
|
|
|
|
|
|
|
}else{
|
|
|
|
|
} else {
|
|
|
|
|
System.out.println("期望数量>=" + expectLimit + ",现在有" + totalRow + "条,理解为数据读取正确,直接返回POI获取的数据列表...");
|
|
|
|
|
}
|
|
|
|
|
System.out.println("==========================================================================================================");
|
|
|
|
|
return data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 读取指定Sheet的第2个表格
|
|
|
|
|
*
|
|
|
|
|
* @param filePath 文件路径
|
|
|
|
|
* @param sheetIndex 第几个Sheet
|
|
|
|
|
* @param keyword 表格正文上方的文字
|
|
|
|
|
* @param headRows 这个表格上面有几行是表头
|
|
|
|
|
* @param letterIndex 结束的列,如:K
|
|
|
|
|
* @return 表格的数据,不带表头
|
|
|
|
|
* @throws IOException
|
|
|
|
|
*/
|
|
|
|
|
public static List<List<String>> readSecondTable(String filePath, int sheetIndex,
|
|
|
|
|
String keyword, int headRows, String letterIndex) throws IOException {
|
|
|
|
|
int tableWidth = ExcelKit.transLetter2Num(letterIndex) + 1;
|
|
|
|
|
return readSecondTable(filePath, sheetIndex, keyword, headRows, tableWidth);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 读取指定Sheet的第2个表格
|
|
|
|
|
*
|
|
|
|
|
* @param filePath 文件路径
|
|
|
|
|
* @param sheetIndex 第几个Sheet
|
|
|
|
|
* @param keyword 表格正文上方的文字
|
|
|
|
|
* @param headRows 这个表格上面有几行是表头
|
|
|
|
|
* @param tableWidth 表格的宽度
|
|
|
|
|
* @return 表格的数据,不带表头
|
|
|
|
|
* @throws IOException
|
|
|
|
|
*/
|
|
|
|
|
public static List<List<String>> readSecondTable(String filePath, int sheetIndex,
|
|
|
|
|
String keyword, int headRows, int tableWidth) throws IOException {
|
|
|
|
|
List<List<String>> dataList = new ArrayList<>();
|
|
|
|
|
FileInputStream fis = new FileInputStream(filePath);
|
|
|
|
|
Workbook workbook = new XSSFWorkbook(fis);
|
|
|
|
|
Sheet sheet = workbook.getSheetAt(sheetIndex);
|
|
|
|
|
int rowIndex = 0;
|
|
|
|
|
//从rowIndex开始,向下面查找,直到第一列中出现文字“自动计算招生数、在校生数”,此行的再下一行就是真正的第二个表格的开始位置
|
|
|
|
|
int start = -1, end = -1;
|
|
|
|
|
|
|
|
|
|
//找到开始行
|
|
|
|
|
for (; rowIndex <= sheet.getLastRowNum(); rowIndex++) {
|
|
|
|
|
Row row = sheet.getRow(rowIndex);
|
|
|
|
|
if (row != null && row.getCell(0) != null
|
|
|
|
|
&& row.getCell(0).toString().contains(keyword)) {
|
|
|
|
|
if (start == -1)
|
|
|
|
|
start = rowIndex;
|
|
|
|
|
}
|
|
|
|
|
if (start > 0 && row == null) {
|
|
|
|
|
end = rowIndex - 1;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
start += headRows;//第二个表的表头有几行
|
|
|
|
|
//输出第二个表格的数据
|
|
|
|
|
for (rowIndex = start; rowIndex <= end; rowIndex++) {
|
|
|
|
|
Row row = sheet.getRow(rowIndex);
|
|
|
|
|
List<String> rowData = new ArrayList<>();
|
|
|
|
|
for (int j = 0; j < tableWidth; j++) {
|
|
|
|
|
Cell cell = row.getCell(j);
|
|
|
|
|
// 如果单元格是公式类型
|
|
|
|
|
if (cell.getCellType() == CellType.FORMULA) {
|
|
|
|
|
// 计算公式结果
|
|
|
|
|
cell.setCellType(CellType.NUMERIC);
|
|
|
|
|
}
|
|
|
|
|
rowData.add(ExcelKit.readCell(cell));
|
|
|
|
|
}
|
|
|
|
|
dataList.add(rowData);
|
|
|
|
|
}
|
|
|
|
|
workbook.close();
|
|
|
|
|
fis.close();
|
|
|
|
|
return dataList;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|