使用jxl读取excel表格后如何计算表格中有多少人并输入到swing表格中
2条回答 默认 最新
关注import java.io.File; import java.util.ArrayList; import java.util.List; import jxl.Cell; import jxl.Sheet; import jxl.Workbook; public class ExcelUtils { public static int countRows(File file) throws Exception { Workbook workbook = Workbook.getWorkbook(file); Sheet sheet = workbook.getSheet(0); // 假设数据在第一个sheet中 int rows = sheet.getRows(); int count = 0; for (int i = 1; i < rows; i++) { // 假设第一行是表头 Cell[] row = sheet.getRow(i); if (row[0].getContents().trim().length() > 0) { count++; } } workbook.close(); return count; } public static List<String[]> readExcel(File file) throws Exception { List<String[]> list = new ArrayList<>(); Workbook workbook = Workbook.getWorkbook(file); Sheet sheet = workbook.getSheet(0); // 假设数据在第一个sheet中 int rows = sheet.getRows(); for (int i = 1; i < rows; i++) { // 假设第一行是表头 Cell[] row = sheet.getRow(i); if (row[0].getContents().trim().length() > 0) { String[] data = new String[row.length]; for (int j = 0; j < row.length; j++) { data[j] = row[j].getContents(); } list.add(data); } } workbook.close(); return list; } }解决 无用评论 打赏 举报