1、构造数据源:
package test; import java.util.ArrayList; public class CrossReportFactory { public static Collection getData(){ List<Map<Object, Object>> subGuestName = new ArrayList<Map<Object, Object>>(); //第一行A1 subGuestNameInit(subGuestName, "C1", "A1","group1", "data1"); subGuestNameInit(subGuestName, "C2", "A1","group1", "data12"); subGuestNameInit(subGuestName, "C3", "A1","group1", "data13"); //第二行A2 subGuestNameInit(subGuestName, "C1", "A2","group1", "data123"); subGuestNameInit(subGuestName, "C2", "A2","group1", "data1234"); subGuestNameInit(subGuestName, "C3", "A2","group1", "data12345"); //第三行还是按C1、C2、C3分3列,但却又按row2分多行 subGuestNameInit(subGuestName, "C1", "A3","g2","d1"); subGuestNameInit(subGuestName, "C2", "A3","g2", "d12"); subGuestNameInit(subGuestName, "C3", "A3","g2", "d123"); subGuestNameInit(subGuestName, "C1", "A3","g3","d11"); subGuestNameInit(subGuestName, "C2", "A3","g3", "d22"); subGuestNameInit(subGuestName, "C3", "A3","g3", "d33"); return subGuestName; } public static void subGuestNameInit(List<Map<Object, Object>> subGuestName,String column,String row,String row2,String value){ Map<Object, Object> guestMap = new HashMap<Object, Object>(); guestMap.put("deptid", row); guestMap.put("deptid2", row2); //第三行继续划分使用 guestMap.put("degree", column); guestMap.put("empid", value); subGuestName.add(guestMap); } }
2、新建一个模版,右击模版名添加Dataset,选择Dataset为刚创建的Dataset。为Dataset添加fields
3、创建交叉报表
row:
column:
value:
交叉报表创建成功。
但此时数据源还不可以,还得这样设置:
右击Detail中的交叉报表,选择Dataset run为"use dataset...",设置Dataset值为$P{REPORT_DATA_SOURCE}即可使用数据源。
详细设置如图:
效果如图:
最后交叉报表如图:
结果:
真正使用时隐藏掉红色部分即可达到要求。