问题
I am using JasperReports and I cannot find the way to create consecutive tables. When the first one is filled in, the next one will cover it instead of being shifted.
Did anyone face this problem before?
UPDATE
I am using the subreport with two detail bands and one table into each of the detail bands.
So far I generate the page for the parent report but the subreport area is blank.
This is the code where I interact with the reports:
try {
HashMap param = new HashMap();
JRBeanCollectionDataSource tableA = new JRBeanCollectionDataSource(tableAItems);
param.put("AtableDatasource", tableA);
JRBeanCollectionDataSource tableB = new JRBeanCollectionDataSource(tableBItems);
param.put("BtableDatasource", tableB);
param.put("tableHeadA","TABLE A HEADER");
param.put("column1AHead","A COL 1");
param.put("column2AHead","A COL 2");
param.put("column3AHead","A COL 3");
param.put("header","SAMPLE REPORT");
param.put("theDetails", "THE DETAILS");
param.put("detail1Label", "DETAIL BAND 1");
param.put("detail2Label", "DETAIL BAND 2");
InputStream parent = Main.class.getResourceAsStream("/sample_parent.jasper");
JasperPrint jpParent = JasperFillManager.fillReport(parent, param, new JREmptyDataSource(1));
JasperExportManager.exportReportToPdfFile(jpParent, "C:\\REPORTS\\sampleReport.pdf");
} catch (JRException e) {
e.printStackTrace();
}
As usual, the sample code is uploaded to the GitHub repo linked below.
GitHub repo: https://github.com/MichaelKnight/jaspertest.git
回答1:
Your immediate problem is that the frame containing the jr:table
does not have positionType="float"
, you have set it to the jr:table
but you need to set it to frame).
However to better control and achieve your desired layout (since you have tables to the right), consider to create 2 subreport.
Pass to subreport new JREmptyDataSource(1)
as datasource to generate 1 record detail band and your parameter map, to get parameter $P{B3questionsDatasource}
etc. in your subreport.
subreport, containing the table A,B in image, either put them on below each other or use multiple detail band's
<detail> <band height="50"> ... table 1 .... </band> <band height="50"> ... table 2 .... </band> </detail>
sub report, with table C and new table D (as in example above).
In main report included the subreport's on next to each other.
Example
<subreport>
<reportElement x="0" y="20" width="400" height="20" uuid="a7a89ebb-54d4-4b6e-8c9f-c107e8a40bbb"/>
<parametersMapExpression><![CDATA[$P{REPORT_PARAMETERS_MAP}]]></parametersMapExpression>
<dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.JREmptyDataSource(1)]]></dataSourceExpression>
<subreportExpression><![CDATA[$P{SUBREPORT_DIR} + "subreport1.jasper"]]></subreportExpression>
</subreport>
来源:https://stackoverflow.com/questions/34979397/create-consecutive-tables-in-jaspersoft