如何在 jasper 报告生成中使列名跨越多行

发布于 2024-12-17 07:10:20 字数 175 浏览 0 评论 0原文

我已经编写了 jasper 规范来从表数据源生成 PDF。这工作正常。现在我必须添加更多列,并且报告现在看起来不太好。我现在在想是否可以将列名称挤入多行中,例如下面的

维护日期

维护

日期

是否可以在贾斯珀中实现这一目标?

问候, 保罗

I've written jasper specification to generate PDF from a table data source. This is working fine. Now i have to add few more columns and the report is now not looking good. I'm now thinking if I can squeeze in the column names in multiple lines like the one below

Maintenance Date

to

Maintenance

Date

Is it possible to achieve this in Jasper?

Regards,
Paul

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

心碎无痕… 2024-12-24 07:10:20

您的列名称是硬编码的吗?是否只需将“Maintenance Date”更改为“Maintenance\nDate”就有回车符?

注意:您不能向静态文本元素添加“\n”字符。您需要使用文本字段。幸运的是,您只需右键单击 iReport 中的静态文本元素并将其转换为文本字段即可。

我想这可能会解决它。如果没有,那么你可能需要把问题说得更清楚。

Are your column names hard-coded? Do you just need to change "Maintenance Date" to "Maintenance\nDate" to have a carriage return?

Note: you cannot add a "\n" character to a Static Text element. You need to use a Text Field. Fortunately, you can just right-click on a Static Text element in iReport and transform it to a Text Field.

I guess that might solve it. If not, then you may need to make the question clearer.

七堇年 2024-12-24 07:10:20

如果您使用 JasperReports API 您可以使用此示例:

    //Detail
    band = new JRDesignBand();
    band.setHeight(40);

    JRDesignStaticText staticText = new JRDesignStaticText();
    staticText.setX(0);
    staticText.setY(0);
    staticText.setWidth(60);
    staticText.setHeight(20);
    staticText.setMode(ModeEnum.OPAQUE);
    staticText.setHorizontalAlignment(HorizontalAlignEnum.LEFT);
    staticText.setStyle(boldStyle);
    staticText.setText("ID: ");
    staticText.getLineBox().getLeftPen().setLineWidth(1);
    staticText.getLineBox().getTopPen().setLineWidth(1);
    staticText.getLineBox().setLeftPadding(10);
    band.addElement(staticText);

    textField = new JRDesignTextField();
    textField.setX(60);
    textField.setY(0);
    textField.setWidth(200);
    textField.setHeight(20);
    textField.setHorizontalAlignment(HorizontalAlignEnum.LEFT);
    textField.setStyle(normalStyle);
    expression = new JRDesignExpression();
    expression.setValueClass(java.lang.Integer.class);
    expression.setText("$F{Id}");
    textField.setExpression(expression);
    textField.getLineBox().getTopPen().setLineWidth(1);
    textField.getLineBox().getRightPen().setLineWidth(1);
    textField.getLineBox().setLeftPadding(10);
    band.addElement(textField);

    staticText = new JRDesignStaticText();
    staticText.setX(0);
    staticText.setY(20);
    staticText.setWidth(60);
    staticText.setHeight(20);
    staticText.setMode(ModeEnum.OPAQUE);
    staticText.setHorizontalAlignment(HorizontalAlignEnum.LEFT);
    staticText.setStyle(boldStyle);
    staticText.setText("Name: ");
    staticText.getLineBox().getLeftPen().setLineWidth(1);
    staticText.getLineBox().getBottomPen().setLineWidth(1);
    staticText.getLineBox().setLeftPadding(10);
    band.addElement(staticText);


    textField = new JRDesignTextField();
    textField.setStretchWithOverflow(true);
    textField.setX(60);
    textField.setY(20);
    textField.setWidth(200);
    textField.setHeight(20);
    textField.setPositionType(PositionTypeEnum.FLOAT);
    textField.setStyle(normalStyle);
    expression = new JRDesignExpression();
    expression.setValueClass(java.lang.String.class);
    expression.setText("$F{FirstName} + \" \" + $F{LastName}");
    textField.setExpression(expression);
    textField.getLineBox().getRightPen().setLineWidth(1);
    textField.getLineBox().getBottomPen().setLineWidth(1);
    textField.getLineBox().setLeftPadding(10);
    band.addElement(textField);

    ((JRDesignSection) jasperDesign.getDetailSection()).addBand(band);

结果将是:

< img src="https://i.sstatic.net/gAibA.png" alt="在此处输入图像描述">

这与 jrxml 文件的此片段几乎相同:

<detail>
    <band height="40" splitType="Stretch">
        <staticText>
            <reportElement x="0" y="0" width="60" height="20"/>
            <box leftPadding="10">
                <topPen lineWidth="1.0"/>
                <leftPen lineWidth="1.0"/>
            </box>
            <textElement/>
            <text><![CDATA[ID: ]]></text>
        </staticText>
        <textField>
            <reportElement x="60" y="0" width="200" height="20"/>
            <box leftPadding="10">
                <topPen lineWidth="1.0"/>
                <rightPen lineWidth="1.0"/>
            </box>
            <textElement/>
            <textFieldExpression><![CDATA[$F{Id}]]></textFieldExpression>
        </textField>
        <staticText>
            <reportElement x="0" y="20" width="60" height="20"/>
            <box leftPadding="10">
                <leftPen lineWidth="1.0"/>
                <bottomPen lineWidth="1.0"/>
            </box>
            <textElement/>
            <text><![CDATA[Name: ]]></text>
        </staticText>
        <textField>
            <reportElement x="60" y="20" width="200" height="20"/>
            <box leftPadding="10">
                <bottomPen lineWidth="1.0"/>
                <rightPen lineWidth="1.0"/>
            </box>
            <textElement/>
            <textFieldExpression><![CDATA[$F{FirstName} + " " + $F{LastName}]]></textFieldExpression>
        </textField>
    </band>
</detail>

If you are using JasperReports API you can use this sample:

    //Detail
    band = new JRDesignBand();
    band.setHeight(40);

    JRDesignStaticText staticText = new JRDesignStaticText();
    staticText.setX(0);
    staticText.setY(0);
    staticText.setWidth(60);
    staticText.setHeight(20);
    staticText.setMode(ModeEnum.OPAQUE);
    staticText.setHorizontalAlignment(HorizontalAlignEnum.LEFT);
    staticText.setStyle(boldStyle);
    staticText.setText("ID: ");
    staticText.getLineBox().getLeftPen().setLineWidth(1);
    staticText.getLineBox().getTopPen().setLineWidth(1);
    staticText.getLineBox().setLeftPadding(10);
    band.addElement(staticText);

    textField = new JRDesignTextField();
    textField.setX(60);
    textField.setY(0);
    textField.setWidth(200);
    textField.setHeight(20);
    textField.setHorizontalAlignment(HorizontalAlignEnum.LEFT);
    textField.setStyle(normalStyle);
    expression = new JRDesignExpression();
    expression.setValueClass(java.lang.Integer.class);
    expression.setText("$F{Id}");
    textField.setExpression(expression);
    textField.getLineBox().getTopPen().setLineWidth(1);
    textField.getLineBox().getRightPen().setLineWidth(1);
    textField.getLineBox().setLeftPadding(10);
    band.addElement(textField);

    staticText = new JRDesignStaticText();
    staticText.setX(0);
    staticText.setY(20);
    staticText.setWidth(60);
    staticText.setHeight(20);
    staticText.setMode(ModeEnum.OPAQUE);
    staticText.setHorizontalAlignment(HorizontalAlignEnum.LEFT);
    staticText.setStyle(boldStyle);
    staticText.setText("Name: ");
    staticText.getLineBox().getLeftPen().setLineWidth(1);
    staticText.getLineBox().getBottomPen().setLineWidth(1);
    staticText.getLineBox().setLeftPadding(10);
    band.addElement(staticText);


    textField = new JRDesignTextField();
    textField.setStretchWithOverflow(true);
    textField.setX(60);
    textField.setY(20);
    textField.setWidth(200);
    textField.setHeight(20);
    textField.setPositionType(PositionTypeEnum.FLOAT);
    textField.setStyle(normalStyle);
    expression = new JRDesignExpression();
    expression.setValueClass(java.lang.String.class);
    expression.setText("$F{FirstName} + \" \" + $F{LastName}");
    textField.setExpression(expression);
    textField.getLineBox().getRightPen().setLineWidth(1);
    textField.getLineBox().getBottomPen().setLineWidth(1);
    textField.getLineBox().setLeftPadding(10);
    band.addElement(textField);

    ((JRDesignSection) jasperDesign.getDetailSection()).addBand(band);

The result will be:

enter image description here

This is almost identical to this snippet of jrxml file:

<detail>
    <band height="40" splitType="Stretch">
        <staticText>
            <reportElement x="0" y="0" width="60" height="20"/>
            <box leftPadding="10">
                <topPen lineWidth="1.0"/>
                <leftPen lineWidth="1.0"/>
            </box>
            <textElement/>
            <text><![CDATA[ID: ]]></text>
        </staticText>
        <textField>
            <reportElement x="60" y="0" width="200" height="20"/>
            <box leftPadding="10">
                <topPen lineWidth="1.0"/>
                <rightPen lineWidth="1.0"/>
            </box>
            <textElement/>
            <textFieldExpression><![CDATA[$F{Id}]]></textFieldExpression>
        </textField>
        <staticText>
            <reportElement x="0" y="20" width="60" height="20"/>
            <box leftPadding="10">
                <leftPen lineWidth="1.0"/>
                <bottomPen lineWidth="1.0"/>
            </box>
            <textElement/>
            <text><![CDATA[Name: ]]></text>
        </staticText>
        <textField>
            <reportElement x="60" y="20" width="200" height="20"/>
            <box leftPadding="10">
                <bottomPen lineWidth="1.0"/>
                <rightPen lineWidth="1.0"/>
            </box>
            <textElement/>
            <textFieldExpression><![CDATA[$F{FirstName} + " " + $F{LastName}]]></textFieldExpression>
        </textField>
    </band>
</detail>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文