Remove template row in JXLS when input list is empty

99封情书 提交于 2019-12-05 21:54:12

You can use <jx:if> tags in your excel template. For example if you have a template similar to the following

Row 1: <jx:if test="${!empty someData}">
Row 2: place holders for data that will be printed in the loop 
Row 3: </jx:if>

If someData is not empty then rows will be printed in the output but if someData is empty then no rows will be printed by this template.

I hope I could make it clear. Please see http://jxls.sourceforge.net/reference/tags.html for more information about tags.

I think this is possible via POI - perhaps even POI object interface of JXLS:

From http://poi.apache.org/spreadsheet/how-to.html:
Modifying the file you have read in is simple. You retrieve the object via an assessor method, remove it via a parent object's remove method (sheet.removeRow(hssfrow)) and create objects just as you would if creating a new xls. When you are done modifying cells just call workbook.write(outputstream) just as you did above.

From http://jxls.sourceforge.net/reference/customprocessor.html:
With Row object you have access to related POI objects to modify cell style if required.

Another reason the rows do not display based on the jx:if condition is if there is some space before the jx:if tag

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!