<dependency> <groupId>org.jxls</groupId> <artifactId>jxls-core</artifactId> <version>2.8.0</version> </dependency> <html xmlns:jx="http://jxls.sf.net/jxls-core" xmlns="http://www.w3.org/1999/xhtml" xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"> <body> <table> <tr> <th>Name</th> <th>Age</th> </tr> <jx:forEach items="${employees}" var="employee"> <tr> <td>${employee.name}</td> <td>${employee.age}</td> </tr> </jx:forEach> </table> </body> </html> public class ExcelGenerator { public static void main(String[] args) throws IOException { List<Employee> employees = getEmployeeData(); try (InputStream is = ExcelGenerator.class.getResourceAsStream("/path/to/template.xlsx")) { try (OutputStream os = new FileOutputStream("/path/to/output.xlsx")) { Context context = new Context(); context.putVar("employees", employees); JxlsHelper.getInstance().processTemplate(is, os, context); } } } private static List<Employee> getEmployeeData() { } }


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