本文介绍了设置具有标题和细节带的jasper子报告的边框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个grails项目,该项目使用jasper插件下载pdf和doc格式的文档。

I am working on a grails project that use jasper plugin for downloading a document in pdf and doc format.

我有几个jasper子报表并在动态中使用这些子报表jasper以pdf和docx格式下载文档。我正在使用动态jasper报告,因为jasper子报告的位置可能会有所不同。

I have several jasper subreports and using these subreports in dynamic jasper to download the document in pdf and docx format. I am using dynamic jasper report because the positions of jasper subreport may vary.

我的jasper子报告有标题和细节带。

My jasper sub report have a title and a detail band.

输出

现在我的问题是边界。需要边框,如:

Now my problem is a border. A border is required like:

我试图设置矩形,帧但都失败了,因为两个乐队没有共享一个上腭(组件)。

I tried to set rectangle, frame but all failed because two bands did not share one palate(component).

我的要求是通过jasper报告或动态jasper的边框。我不知道如何设置边框。

My requirement is a border via jasper report or via dynamic jasper. I have no idea how to set the border.

编辑............................... .........................................

我还试图通过动态jasper代码使用框架和矩形设置边框,输出为:

I also tried to set the border using a frame and rectangle via dynamic jasper code and the output is:

框架和矩形未覆盖整个子报表。这是我的代码:

frame and rectangle not covering whole subreport. Here is my code:

JRDesignRectangle rectangle = new JRDesignRectangle();
//JRDesignFrame rectangle = new JRDesignFrame();
rectangle.setX(subReport.getX());
rectangle.setY(subReport.getY());
rectangle.setHeight(subReport.getHeight());
rectangle.setWidth(subReport.getWidth());
rectangle.setPositionType(PositionTypeEnum.FLOAT);
band.addElement(rectangle);


推荐答案

如果您使用的是jasper报告插件,则可以打开JRXML文件并说出类似

If you are using jasper report plugin, you can open the JRXML file and say something like

 <box>
        <topPen lineWidth="1.0"/>
        <leftPen lineWidth="1.0"/>
        <bottomPen lineWidth="1.0"/>
        <rightPen lineWidth="1.0"/>
    </box>

Jasper报告附带一个名为' IReport Designer的优秀设计师。您可以在IReport设计器中使用概念
frames 并将子报告放在框架内,然后在框架本身上应用边框
属性。您还可以找到有用的。我会
肯定推荐这些链接。

Jasper reports come with an excellent designer called 'IReport Designer'. You can use conceptof frames in IReport designer and put your sub-report inside the frame and then apply the borderproperties on the frame itself. You can also find BorderAroundTable useful. I woulddefinitely recommend these links as well.

如果这个解决方案,请告诉我们适用于你。

Let us know if this solution works for you.

如果它可以用于具有摘要和页眉的子报表,那么它也可以帮助你的情况。

If it can work for subreport having summary and page header, then it can help your case as well.

编辑和添加有边框的主报表和子报表代码

主报表源代码

<?xml version="1.0" encoding="UTF-8"?>
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="testborder" language="groovy" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20">
    <property name="ireport.zoom" value="1.0"/>
    <property name="ireport.x" value="0"/>
    <property name="ireport.y" value="0"/>
    <background>
        <band splitType="Stretch"/>
    </background>
    <detail>
        <band height="421" splitType="Stretch">
            <subreport>
                <reportElement x="25" y="148" width="200" height="100"/>
                <dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.JREmptyDataSource()]]></dataSourceExpression>
                <subreportExpression><![CDATA["C:\\jaspersamples\\testborder_subreport1.jasper"]]></subreportExpression>
            </subreport>
            <frame>
                <reportElement x="45" y="119" width="390" height="176"/>
                <box>
<topPen lineWidth="2.0" lineStyle="Solid"/>
<leftPen lineWidth="2.0" lineStyle="Solid"/>

                    <bottomPen lineWidth="2.0" lineStyle="Solid"/>
                    <rightPen lineWidth="2.0" lineStyle="Solid"/>
                </box>
            </frame>
        </band>
    </detail>
</jasperReport>

子报告源代码

<?xml version="1.0" encoding="UTF-8"?>
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="testborder_subreport1" language="groovy" pageWidth="802" pageHeight="555" orientation="Landscape" whenNoDataType="AllSectionsNoDetail" columnWidth="802" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0">
    <property name="ireport.zoom" value="1.0"/>
    <property name="ireport.x" value="0"/>
    <property name="ireport.y" value="0"/>
    <background>
        <band splitType="Stretch"/>
    </background>
    <pageHeader>
        <band height="29" splitType="Stretch">
            <staticText>
                <reportElement x="317" y="5" width="100" height="20"/>
                <textElement/>
                <text><![CDATA[HELLO TEST]]></text>
            </staticText>
        </band>
    </pageHeader>
    <summary>
        <band height="29" splitType="Stretch">
            <staticText>
                <reportElement x="317" y="0" width="100" height="20"/>
                <textElement/>
                <text><![CDATA[i am testing BORDER]]></text>
            </staticText>
        </band>
    </summary>
</jasperReport>

输出有点像这样

这篇关于设置具有标题和细节带的jasper子报告的边框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 09:54