报告中具有预定义列数

时间:2017-06-07 06:34:27

标签: jasper-reports

我正在尝试在jasper报告中逐列显示数据以实现相同的目标我创建了具有A4大小的jasper报告,并将页面属性垂直更改为3列,以便在3列中垂直显示数据。

问题是如果我有一条记录然后它显示正确的数据,但如果我有多个数据然后它打印出现有数据的数据,我不想要有任何方式我们可以强迫jasper并行显示数据另一种是垂直方式,而不是相互打印。

下面是我用于插入语句测试目的的示例表。

 create table jasper_demo(  
  no         number(2,0),  
  name       varchar2(14),  
  loc        varchar2(13)  
 )

 insert into jasper_demo values(10, 'ACCOUNTING', 'NEW YORK');

 insert into jasper_demo values(20, 'INFLATION', 'LONDON');

 insert into jasper_demo values(30, 'GAMMA-RAYS', 'CHINA');

 insert into jasper_demo values(40, 'HEXA-RAYS', 'JAPAN');

从db(oracle 11g)

检索数据的查询
SELECT
b.no,b.name,b.loc
FROM
(SELECT LEVEL  as lvl from dual CONNECT BY LEVEL <= 24)
 a
full outer JOIN
(  SELECT    rownum  as lvl,
      no,
      name,
      loc
     from jasper_demo 
  )   b ON a.lvl = b.lvl
order by a.lvl

碧玉的来源:

<?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="Blank_A4_1" columnCount="3" pageWidth="595" pageHeight="842" columnWidth="185" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="c58759d6-4d76-455f-89bd-1a9b204e0bc8">
    <queryString>
        <![CDATA[SELECT
    b.no,b.name,b.loc
FROM
    (SELECT LEVEL  as lvl from dual CONNECT BY LEVEL <= 24)
     a
full outer JOIN
    (  SELECT    rownum  as lvl,
      no,
      name,
      loc
     from jasper_demo 
      )   b ON a.lvl = b.lvl
   order by a.lvl]]>
    </queryString>
    <field name="NO" class="java.math.BigDecimal"/>
    <field name="NAME" class="java.lang.String"/>
    <field name="LOC" class="java.lang.String"/>
    <group name="NO">
        <groupExpression><![CDATA[$F{NO}]]></groupExpression>
    </group>
    <group name="NAME">
        <groupExpression><![CDATA[$F{NAME}]]></groupExpression>
    </group>
    <group name="LOC">
        <groupExpression><![CDATA[$F{LOC}]]></groupExpression>
    </group>
    <detail>
        <band height="128" splitType="Stretch">
            <textField>
                <reportElement x="0" y="10" width="100" height="30" uuid="f8ac39df-75ca-44e6-aca6-eef38ff74f73">
                    <printWhenExpression><![CDATA[$F{NO}!=null]]></printWhenExpression>
                </reportElement>
                <textFieldExpression><![CDATA[$F{NO}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="0" y="45" width="100" height="30" uuid="44c44cc6-c7d4-44c5-8907-af98439b2fc6">
                    <printWhenExpression><![CDATA[$F{NO}!=null]]></printWhenExpression>
                </reportElement>
                <textFieldExpression><![CDATA[$F{NAME}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement key="" x="0" y="80" width="100" height="30" uuid="8186d204-5448-49d5-893d-6a953f21cdf8">
                    <printWhenExpression><![CDATA[$F{NO}!=null]]></printWhenExpression>
                </reportElement>
                <textFieldExpression><![CDATA[$F{LOC}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="202" y="9" width="100" height="30" uuid="6fc3b438-b12d-4f43-b4b3-c040806f2ac1">
                    <printWhenExpression><![CDATA[$F{NO}!=null]]></printWhenExpression>
                </reportElement>
                <textFieldExpression><![CDATA[$F{NO}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="202" y="44" width="100" height="30" uuid="31af60e9-505b-438d-9eb3-4fc8d2c9bf4c">
                    <printWhenExpression><![CDATA[$F{NO}!=null]]></printWhenExpression>
                </reportElement>
                <textFieldExpression><![CDATA[$F{NAME}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="202" y="79" width="100" height="30" uuid="48ffb03f-b785-42b6-b2b7-4fe087d3550e">
                    <printWhenExpression><![CDATA[$F{NO}!=null]]></printWhenExpression>
                </reportElement>
                <textFieldExpression><![CDATA[$F{LOC}]]></textFieldExpression>
            </textField>
        </band>
    </detail>
</jasperReport>

我面临的问题:

This is the screen shot of wrong display

1 个答案:

答案 0 :(得分:3)

报告的设计是错误的。

Wrong design

正确的&#34;列&#34;有三个textFields超出了列的区域。

您已为报告设置此属性:

  • =信息columnCount&#34; 3&#34;
  • pageWidth =&#34; 595&#34;
  • columnWidth时=&#34; 185&#34;

并且textFields从第二(右)列的x位置的宽度大于 185

修复非常简单。您应该为textField设置所有元素都在列的大小和位置。

良好设计的样本

模板

所有元素都位于报告栏的区域。

<?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="Report with 3 columns" columnCount="3" pageWidth="595" pageHeight="842" columnWidth="185" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="c58759d6-4d76-455f-89bd-1a9b204e0bc8">
    <property name="com.jaspersoft.studio.data.defaultdataadapter" value="users.csv"/>
    <field name="category" class="java.lang.String"/>
    <field name="user" class="java.lang.String"/>
    <field name="status" class="java.lang.String"/>
    <detail>
        <band height="128" splitType="Stretch">
            <textField>
                <reportElement x="0" y="10" width="90" height="30" uuid="f8ac39df-75ca-44e6-aca6-eef38ff74f73">
                    <property name="com.jaspersoft.studio.unit.width" value="pixel"/>
                    <printWhenExpression><![CDATA[$F{category}!=null]]></printWhenExpression>
                </reportElement>
                <textFieldExpression><![CDATA[$F{category}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="0" y="45" width="90" height="30" uuid="44c44cc6-c7d4-44c5-8907-af98439b2fc6">
                    <printWhenExpression><![CDATA[$F{category}!=null]]></printWhenExpression>
                </reportElement>
                <textFieldExpression><![CDATA[$F{user}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement key="" x="0" y="80" width="90" height="30" uuid="8186d204-5448-49d5-893d-6a953f21cdf8">
                    <printWhenExpression><![CDATA[$F{category}!=null]]></printWhenExpression>
                </reportElement>
                <textFieldExpression><![CDATA[$F{status}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="90" y="10" width="90" height="30" uuid="6fc3b438-b12d-4f43-b4b3-c040806f2ac1">
                    <printWhenExpression><![CDATA[$F{category}!=null]]></printWhenExpression>
                </reportElement>
                <textFieldExpression><![CDATA[$F{category}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="90" y="45" width="90" height="30" uuid="31af60e9-505b-438d-9eb3-4fc8d2c9bf4c">
                    <printWhenExpression><![CDATA[$F{category}!=null]]></printWhenExpression>
                </reportElement>
                <textFieldExpression><![CDATA[$F{user}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="90" y="80" width="90" height="30" uuid="48ffb03f-b785-42b6-b2b7-4fe087d3550e">
                    <printWhenExpression><![CDATA[$F{category}!=null]]></printWhenExpression>
                </reportElement>
                <textFieldExpression><![CDATA[$F{status}]]></textFieldExpression>
            </textField>
        </band>
    </detail>
</jasperReport>

Jaspersoft Studio 的设计如下:

Right design

数据源

我使用过简单的 csv 数据源:

category,user,status
1,user1,WORK
1,user1,HOLIDAY
1,user2,SICK
2,user1,WORK
2,user2,WORK
2,user2,HOLIDAY
2,user3,HOLIDAY
2,user4,SICK
3,user1,HOLIDAY
3,user3,HOLIDAY
3,user5,HOLIDAY
4,user1,WORK
4,user1,HOLIDAY
4,user2,SICK
4,user2,WORK
4,user2,SICK
4,user3,HOLIDAY
4,user4,HOLIDAY
4,user5,HOLIDAY

输出结果

输出结果是每行3列(一列有两个textFields) - 每个伪行有6列textFields。

Output result at JSS

重叠效应消失了。