1

我的应用程序中有不同的模块。每个模块都可以导出为 excel、word 和 pdf 格式。报告格式为横向纵向。现在我需要编译所有这些报告并作为一个单一的导出。但我面临一个问题,即在导出时,DynamicJasper仅以单一格式显示,即横向纵向

如何使用DynamicJasper API在单个报告中使用两种格式显示我的报告?

4

2 回答 2

2

您可以创建主报表并向其添加子报表,这是主报表的示例以及如何添加子报表:

public DynamicReport buildDynamicReport() throws ReportDocumentGenerationException {
  DynamicReportBuilder drb = new DynamicReportBuilder();
  drb.setDetailHeight(detailHeight)     
  .setMargins(properties.getReportMargins().getTopMargin(), properties.getReportMargins().getBottomMargin(), properties.getReportMargins().getLeftMargin(), properties.getReportMargins().getRightMargin())     
  .setDefaultStyles(null, null, null, getSpoolStyle(SpoolRow.PLAIN_ATTRIBUTE))    
  .setPageSizeAndOrientation(new Page(**/*Your document dimensions and orientation*/**)
  .setColumnsPerPage(1);
   for(ReportDocumentInformationPage page: reportInformation.getPaginas()){
            drb.addConcatenatedReport(getPageSubReport(page.getPageNumber()),new ClassicLayoutManager(),"DS"+page.getPageNumber().toString(),DJConstants.DATA_SOURCE_ORIGIN_PARAMETER, DJConstants.DATA_SOURCE_TYPE_JRDATASOURCE,!page.getPageNumber().equals(1));
            params.put("DS"+page.getPageNumber().toString(), getReportJRDataSource(page.getPageNumber())  );
        }
        drb.setUseFullPageWidth(true);
        DynamicReport dr = drb.build();
        return dr;
    }

这是有关如何创建这些子报表的示例:

*private DynamicReport getPageSubReport(int i) throws ReportDocumentGenerationException {
        try{
            DynamicReportBuilder drb = new DynamicReportBuilder();
            drb.setDetailHeight(detailHeight)
            .setReportName("Reporte"+i)
            .setMargins(properties.getReportMargins().getTopMargin(), properties.getReportMargins().getBottomMargin(), properties.getReportMargins().getLeftMargin(), properties.getReportMargins().getRightMargin())
            .setDefaultStyles(null, null, null, getSpoolStyle(SpoolRow.PLAIN_ATTRIBUTE))    
            .setPageSizeAndOrientation(new Page(**/*Your specific Page dimensions and orientation***/)
            .setColumnsPerPage(1);

            AbstractColumn spoolColumn = ColumnBuilder.getNew()     
            .setColumnProperty("value", String.class.getName())     
            .setTitle(null)     
            .setWidth(150)
            .build();       
            spoolColumn.setConditionalStyles(getSpoolConditionalStyle());

            drb.addColumn(spoolColumn);
            drb.setUseFullPageWidth(true);
            drb.addField("attributes", String.class.getName());
            DynamicReport dr = drb.build();
            return dr;
        }catch(ColumnBuilderException cbe){
            cbe.printStackTrace();
            throw new ReportDocumentGenerationException("No se pudo definir correctamente la columna del reporte para la pagina "+i);
        }catch(Exception e){
            e.printStackTrace();
            throw new ReportDocumentGenerationException("No se pudo generar la pagina "+i+" del reporte");
        }
    }*

希望能帮助到你。

于 2013-05-14T15:10:13.100 回答
0

如果您拥有或可以获得 JasperPrint 对象的句柄,那么您可以设置方向:

final JasperDesign jasperDesign = JRXmlLoader.load(someInputStream);
final JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);
final JasperPrint jasperPrint =   jasperPrint = JasperFillManager.fillReport( jasperReport, parameters, dataSourceOrConnection);    
...
jasperPrint.setOrientation(OrientationEnum.LANDSCAPE); // Pick
jasperPrint.setOrientation(OrientationEnum.PORTRAIT);  // One 
...
someJRExporter.exportReport();

您还可以使用 JasperPrint 对象设置页面宽度和高度。

于 2012-09-05T05:39:28.133 回答