以Excel作为模板产生Excel
jxls:http://jxls.sourceforge.net/,产生简单的excel报表还是挺好用到,感觉类似于jsp里面使用el和jstl,不再需要数格子、画格子。
主要类库:commons-jexl.jar和jxls-core.jar。
代码例子
Map params=new HashMap(); response.setContentType("application/vnd.ms-excel"); response.setHeader("Content-Disposition","attachment; filename=baseinfo.xls"); XLSTransformer transformer=new XLSTransformer(); InputStream is=new BufferedInputStream(new FileInputStream(getServletContext().getRealPath( "/MISPackWeb/TeacherManagement/templates/baseinfo.xls"))); HSSFWorkbook workbook=transformer.transformXLS(is,params); OutputStream os=response.getOutputStream(); workbook.write(os); is.close(); os.flush(); os.close();
<jx:forEach items="${requirementItems}" var="item"> ${item.sortOrder}、${item.title}(${item.description})</jx:forEach><jx:if test="${department.chief.payment > 2000.0}"> Chief Name: ${department.chief.name}</jx:if>${researchOrientation.cnName.trim()}