问题
I have a requirement where in I need to print the data in my sub report in horizontal order rather than vertical.
However the master data is still to be presented in vertical order.
The report presentation is something like this below where the Subject column would grow horizontally for each record.
I have tried keeping the Subject records as a subreport to the main report but it does not get printed horizontally.
TeacherId TeacherName Subject1 Subject2 Subject3
1 Tom Physics Chem Bio
2 Sofie Eng History Geography
3 Monique Eng Chem Physics
Checked a few existing answers but no clue.
Any help would be thankful.
回答1:
I would share the changes done to achieve the above output if it helps anyone:
- Create the report to be embedded as a subreport as an independent report.
- Change the printOrder to "horizontal" and Columns: n (where n can be any value greater than 1)
- Save the jrxml file.
- In the master report add the sub report element. while adding chose the option "just add the subreport element".
Go to the Properties tab of the subreport element do the following changes as below:
Subreport Expression: $P{SUBREPORT_DIR}+"SubReportfileName.jasper"
DataSourceExpression: new net.sf.jasperreportsengine.data.JRBeanCollectionDatasource($F{subjects})
, here subjects is the field name for the BO Subjects present as an association in Teacher BO.
来源:https://stackoverflow.com/questions/24241141/printing-a-sub-report-data-horizontally