可以使用 Apache POI 库来读取 Excel 文件并解析数据。首先,需要在项目中引入 Apache POI 的依赖。\n\nxml\n<dependency>\n <groupId>org.apache.poi</groupId>\n <artifactId>poi</artifactId>\n <version>4.1.2</version>\n</dependency>\n\n\n然后,可以使用以下代码来读取 Excel 文件并生成cardAttenDenceList:\n\n```java\nimport org.apache.poi.ss.usermodel.*;\n\nimport java.io.FileInputStream;\nimport java.io.IOException;\nimport java.util.ArrayList;\nimport java.util.List;\n\npublic class ExcelReader {\n public static void main(String[] args) {\n String filePath = "C:\Users\25346\Desktop\3124.xlsx";\n List cardAttenDenceList = readExcel(filePath);\n // 打印读取的数据\n for (CardAttenDence cardAttenDence : cardAttenDenceList) {\n System.out.println(cardAttenDence.getCardID() + " - " + cardAttenDence.getAttenDatatime());\n }\n }\n\n public static List readExcel(String filePath) {\n List cardAttenDenceList = new ArrayList<>();\n\n try (FileInputStream fis = new FileInputStream(filePath);\n Workbook workbook = WorkbookFactory.create(fis)) {\n\n Sheet sheet = workbook.getSheetAt(0);\n\n // 获取列名所在的行\n Row headerRow = sheet.getRow(0);\n\n // 获取列名对应的列索引\n int cardIdColumnIndex = getColumnIndex(headerRow, "CardID");\n int attenDatatimeColumnIndex = getColumnIndex(headerRow, "AttenDatatime");\n\n // 遍历数据行\n for (int rowNum = 1; rowNum <= sheet.getLastRowNum(); rowNum++) {\n Row row = sheet.getRow(rowNum);\n\n // 读取 CardID 列的值\n String cardID = getCellValue(row.getCell(cardIdColumnIndex));\n\n // 读取 AttenDatatime 列的值\n String attenDatatime = getCellValue(row.getCell(attenDatatimeColumnIndex));\n\n // 创建 CardAttenDence 对象并添加到列表中\n cardAttenDenceList.add(new CardAttenDence(cardID, attenDatatime));\n }\n\n } catch (IOException e) {\n e.printStackTrace();\n }\n\n return cardAttenDenceList;\n }\n\n public static int getColumnIndex(Row row, String columnName) {\n for (int i = 0; i < row.getLastCellNum(); i++) {\n Cell cell = row.getCell(i);\n String cellValue = getCellValue(cell);\n if (cellValue.equalsIgnoreCase(columnName)) {\n return i;\n }\n }\n return -1;\n }\n\n public static String getCellValue(Cell cell) {\n if (cell == null) {\n return "";\n }\n if (cell.getCellType() == CellType.STRING) {\n return cell.getStringCellValue();\n } else if (cell.getCellType() == CellType.NUMERIC) {\n return String.valueOf(cell.getNumericCellValue());\n } else if (cell.getCellType() == CellType.BOOLEAN) {\n return String.valueOf(cell.getBooleanCellValue());\n } else if (cell.getCellType() == CellType.BLANK) {\n return "";\n } else {\n return "";\n }\n }\n}\n\nclass CardAttenDence {\n private String cardID;\n private String attenDatatime;\n\n public CardAttenDence(String cardID, String attenDatatime) {\n this.cardID = cardID;\n this.attenDatatime = attenDatatime;\n }\n\n public String getCardID() {\n return cardID;\n }\n\n public String getAttenDatatime() {\n return attenDatatime;\n }\