Java 如何在打印顺序设置为“时自动拉伸明细栏”;“水平”;在JasperReport?

Java 如何在打印顺序设置为“时自动拉伸明细栏”;“水平”;在JasperReport?,java,jasper-reports,Java,Jasper Reports,我有一份横向打印的主要报告。它有5列。 我想在每一列上写一个子报告。所以我创造了这个: 子报告如下所示: 问题是,当我运行时,会出现以下异常: net.sf.jasperreports.engine.JRRuntimeException: Subreport overflowed on a band that does not support overflow. 当jasper reports中有子报表且打印顺序设置为“水平”时,它无法垂直拉伸详细信息栏 我能做些什么来避免这个错误并实现我

我有一份横向打印的主要报告。它有5列。 我想在每一列上写一个子报告。所以我创造了这个:

子报告如下所示:

问题是,当我运行时,会出现以下异常:

net.sf.jasperreports.engine.JRRuntimeException: Subreport overflowed on a band that does not support overflow.
当jasper reports中有子报表且打印顺序设置为“水平”时,它无法垂直拉伸详细信息栏


我能做些什么来避免这个错误并实现我想要的?

我找到了这个问题的解决方案。经过深入搜索,我发现,遗憾的是,在Jasper Reports上没有办法做到这一点,因为不管怎样,当你水平打印一份报告时,“细节”栏永远不会改变它的高度。因此,溢出的子报表或文本字段将引发异常

解决这个问题的方法是不使用报表,例如使用像iText这样的PDF生成器。 如果有人需要,这是我用iText实现所需的代码:

Document document = new Document();
File arquivo = new File("C:\\Users\\Mateus\\Desktop\\testezãozarãozão.pdf");
PdfWriter.getInstance(document, new FileOutputStream(arquivo));
document.open();

LinkedHashMap<Produto, LinkedHashMap<String, List<PrePedidoItem>>> produtos = createStructuredHashMap();

for (Produto produto : produtos.keySet()) {
    PdfPTable table = new PdfPTable(5);
    PdfPCell cellProduto = new PdfPCell();
    Phrase phraseProduto = new Phrase(String.valueOf(produto));
    phraseProduto.setFont(new Font(Font.FontFamily.HELVETICA, 11, Font.BOLD|Font.UNDERLINE, new BaseColor(50, 65, 200)));
    cellProduto.addElement(phraseProduto);
    cellProduto.setColspan(5);
    cellProduto.setHorizontalAlignment(PdfPCell.ALIGN_MIDDLE);
    cellProduto.setBorder(Rectangle.NO_BORDER);
    cellProduto.setPaddingBottom(10);
    cellProduto.setPaddingTop(20);
    table.addCell(cellProduto);
    LinkedHashMap<String, List<PrePedidoItem>> mapas = produtos.get(produto);
    int mapasAdicionados = 0;
    for (String mapa : mapas.keySet()) {
        PdfPCell cellMapa = new PdfPCell();
        Phrase phraseMapa = new Phrase(mapa);
        phraseMapa.setFont(new Font(Font.FontFamily.HELVETICA, 9, Font.BOLD, new BaseColor(215, 100, 0)));
        cellMapa.addElement(phraseMapa);
        List<PrePedidoItem> itensDoMapa = mapas.get(mapa);
        for (PrePedidoItem item : itensDoMapa) {
            DecimalFormat df = new DecimalFormat("###,##0.00");
            Phrase phraseItem = new Phrase(df.format(item.getLargura()) + " x " + df.format(item.getComprimento()));
            phraseItem.setFont(new Font(Font.FontFamily.HELVETICA, 9, Font.NORMAL, BaseColor.BLACK));
            cellMapa.addElement(phraseItem);
        }
        cellMapa.setBorder(Rectangle.NO_BORDER);
        table.addCell(cellMapa);
        mapasAdicionados ++;
        if(mapasAdicionados == 5) {
            mapasAdicionados = 0;
        }
    }
    PdfPCell celulaPreenchimentoMapas = new PdfPCell();
    celulaPreenchimentoMapas.setColspan(5 - mapasAdicionados);
    celulaPreenchimentoMapas.setBorder(Rectangle.NO_BORDER);
    table.addCell(celulaPreenchimentoMapas);
    document.add(table);
}

document.close();
Desktop.getDesktop().open(arquivo);
Document Document=新文档();
文件arquivo=新文件(“C:\\Users\\Mateus\\Desktop\\testezãozarãozão.pdf”);
getInstance(文档,新文件输出流(arquivo));
document.open();
LinkedHashMap produtos=createStructuredHashMap();
for(Produto-Produto:Produto.keySet()){
PdfPTable=新的PdfPTable(5);
PdfPCell cellProduto=新的PdfPCell();
短语phraseProduto=新短语(String.valueOf(produto));
phraseProduto.setFont(新字体(Font.FontFamily.HELVETICA,11,Font.BOLD | Font.UNDERLINE,新基色(50,65,200));
cellProduto.addElement(phraseProduto);
cellProduto.setColspan(5);
cellProduto.setHorizontalAlignment(PdfPCell.Alignment_MIDDLE);
cellProduto.SetBeOrder(矩形,无边框);
cellProduto.设置填充底部(10);
cellProduto.setPaddingTop(20);
表2.addCell(cellProduto);
LinkedHashMap mapas=produto.get(produto);
int mapasAdicionados=0;
for(字符串mapa:mapas.keySet()){
PdfPCell cellMapa=新的PdfPCell();
短语短语mapa=新短语(mapa);
phraseMapa.setFont(新字体(Font.fontfaliam.HELVETICA,9,Font.BOLD,新基色(215,100,0));
cellMapa.addElement(短语mapa);
List itensDoMapa=mapas.get(mapa);
用于(PrePedidoItem项:itensDoMapa){
DecimalFormat df=新的DecimalFormat(“####,##0.00”);
短语短语项=新短语(df.format(item.getLargura())+“x”+df.format(item.getcompremento());
phraseItem.setFont(新字体(Font.FontFamily.HELVETICA,9,Font.NORMAL,BaseColor.BLACK));
cellMapa.附录(措辞项目);
}
cellMapa.setBorder(矩形,无边框);
表1.addCell(cellMapa);
mapasAdicionados++;
if(mapasAdicionados==5){
mapasAdicionados=0;
}
}
PdfPCell CelulaPreencimentomapas=新的PdfPCell();
Celulapreencimentomapas.setColspan(5-mapasAdicionados);
CelulaPreencimentomapas.Setboorder(矩形,无边框);
表1.addCell(celulaPreenchimentoMapas);
文件。添加(表);
}
document.close();
Desktop.getDesktop().open(arquivo);

能否提供jrxml文件?请尝试添加文本字段,并在文本字段内创建实际的字段变量