<dependencies> <dependency> <groupId>org.jxls</groupId> <artifactId>jxls</artifactId> <version>2.9.0</version> </dependency> </dependencies> public class Student { private String name; private int age; // ... public List<Student> getStudents() { List<Student> students = new ArrayList<>(); students.add(new Student("Alice", 18)); students.add(new Student("Bob", 20)); students.add(new Student("Charlie", 22)); return students; } } public class ExcelGenerator { public static void main(String[] args) throws IOException { InputStream templateInputStream = new FileInputStream("template.xls"); Context context = new Context(); context.putVar("students", new Student().getStudents()); try (OutputStream outputStream = new FileOutputStream("output.xls")) { Transformer transformer = TransformerFactory.createTransformer(templateInputStream, outputStream); transformer.transform(context); } } }


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