public class User { private String id; private String name; private int age; } import com.adamsexcel.ExcelReader; import com.adamsexcel.Sheet; import com.adamsexcel.Cell; import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.List; public class ExcelImportTool { public List<User> importExcel(String filePath) throws IOException { List<User> users = new ArrayList<>(); ExcelReader reader = new ExcelReader(filePath); User user = new User(); user.setId(cell.getString()); cell = sheet.getCell(1, i); user.setName(cell.getString()); cell = sheet.getCell(2, i); user.setAge(cell.getInt()); users.add(user); } return users; } } public class Main { public static void main(String[] args) { try { List<User> users = new ExcelImportTool().importExcel("path/to/your/excel/file.xlsx"); for (User user : users) { System.out.println("ID: " + user.getId() + ", Name: " + user.getName() + ", Age: " + user.getAge()); } } catch (IOException e) { e.printStackTrace(); } } }


上一篇:
下一篇:
切换中文