使用ireport3.0与ireport3.5一起设计交叉报表crosstab

交叉报表crosstab:ireport3.0.0右键点击切换到交叉表设计页,首先增加一个dataset,查询sql如下:

 

select user_id_atte, to_char(attendance_time,'yyyy-mm-dd') attendance_time from t_attendance_time t where

t.ATTENDANCE_AVALID='Y'
and t.ATTENDANCE_TIME > to_date('2010-9-10','yyyy-mm-dd')

 

一个交叉报表实例:test.jrxml:

<?xml version="1.0" encoding="UTF-8"  ?>
<!-- Created with iReport - A designer for JasperReports -->
<!DOCTYPE jasperReport PUBLIC "//JasperReports//DTD Report Design//EN"

"http://jasperreports.sourceforge.net/dtds/jasperreport.dtd">
<jasperReport
   name="crosstab2"
   columnCount="1"
   printOrder="Vertical"
   orientation="Portrait"
   pageWidth="595"
   pageHeight="842"
   columnWidth="535"
   columnSpacing="0"
   leftMargin="20"
   rightMargin="20"
   topMargin="20"
   bottomMargin="20"
   whenNoDataType="NoPages"
   isTitleNewPage="false"
   isSummaryNewPage="false">
 <property name="ireport.scriptlethandling" value="0" />
 <property name="ireport.encoding" value="UTF-8" />
 <import value="java.util.*" />
 <import value="net.sf.jasperreports.engine.*" />
 <import value="net.sf.jasperreports.engine.data.*" />

 <style
  name="Crosstab Data Text"
  isDefault="false"
  hAlign="Center"
 >
 </style>

 <subDataset name="dataset1" >

  <queryString><![CDATA[select user_id_atte, to_char(attendance_time,'yyyy-mm-dd') attendance_time from

t_attendance_time t where t.ATTENDANCE_AVALID='Y'
and t.ATTENDANCE_TIME > to_date('2010-9-10','yyyy-mm-dd')]]></queryString>

  <field name="USER_ID_ATTE" class="java.math.BigDecimal"/>
  <field name="ATTENDANCE_TIME" class="java.lang.String"/>

 </subDataset>

 <queryString><![CDATA[select user_id,username from t_user]]></queryString>

 <field name="USER_ID" class="java.math.BigDecimal"/>
 <field name="USERNAME" class="java.lang.String"/>

  <background>
   <band height="0"  isSplitAllowed="true" >
   </band>
  </background>
  <title>
   <band height="79"  isSplitAllowed="true" >
    <staticText>
     <reportElement
      x="232"
      y="28"
      width="100"
      height="20"
      key="staticText"/>
     <box></box>
     <textElement>
      <font/>
     </textElement>
    <text><![CDATA[Static text]]></text>
    </staticText>
   </band>
  </title>
  <pageHeader>
   <band height="0"  isSplitAllowed="true" >
   </band>
  </pageHeader>
  <columnHeader>
   <band height="0"  isSplitAllowed="true" >
   </band>
  </columnHeader>
  <detail>
   <band height="0"  isSplitAllowed="true" >
   </band>
  </detail>
  <columnFooter>
   <band height="0"  isSplitAllowed="true" >
   </band>
  </columnFooter>
  <pageFooter>
   <band height="50"  isSplitAllowed="true" >
    <textField isStretchWithOverflow="false" isBlankWhenNull="false" evaluationTime="Now"

hyperlinkType="None"  hyperlinkTarget="Self" >
     <reportElement
      x="232"
      y="12"
      width="80"
      height="20"
      key="textField"/>
     <box></box>
     <textElement textAlignment="Right">
      <font/>
     </textElement>
    <textFieldExpression   class="java.lang.String"><![CDATA["Page "+$V{PAGE_NUMBER}+"

of"]]></textFieldExpression>
    </textField>
    <textField isStretchWithOverflow="false" isBlankWhenNull="false" evaluationTime="Report"

hyperlinkType="None"  hyperlinkTarget="Self" >
     <reportElement
      x="312"
      y="12"
      width="40"
      height="20"
      key="textField"/>
     <box></box>
     <textElement>
      <font/>
     </textElement>
    <textFieldExpression   class="java.lang.String"><![CDATA[" " + $V{PAGE_NUMBER}]]

></textFieldExpression>
    </textField>
   </band>
  </pageFooter>
  <summary>
   <band height="802"  isSplitAllowed="true" >
    <crosstab >
     <reportElement
      x="0"
      y="0"
      width="555"
      height="802"
      key="crosstab"/>
     <crosstabDataset>
      <dataset >
       <datasetRun subDataset="dataset1">
        <connectionExpression><![CDATA[$P

{REPORT_CONNECTION}]]></connectionExpression>
       </datasetRun>
      </dataset>
     </crosstabDataset>
     <crosstabHeaderCell>      

<cellContents mode="Transparent">
     <box></box>
    <rectangle>
     <reportElement
      x="0"
      y="0"
      width="70"
      height="30"
      key="rectangle-1"/>
     <graphicElement stretchType="NoStretch"/>
    </rectangle>
    <line direction="TopDown">
     <reportElement
      x="0"
      y="1"
      width="70"
      height="28"
      key="line-1"/>
     <graphicElement stretchType="NoStretch"/>
    </line>
    <staticText>
     <reportElement
      x="45"
      y="3"
      width="22"
      height="12"
      key="staticText-1"/>
     <box></box>
     <textElement>
      <font pdfFontName="Helvetica-Bold" size="8" isBold="true"/>
     </textElement>
    <text><![CDATA[日期]]></text>
    </staticText>
    <staticText>
     <reportElement
      x="2"
      y="16"
      width="27"
      height="11"
      key="staticText-1"/>
     <box></box>
     <textElement>
      <font pdfFontName="Helvetica-Bold" size="8" isBold="true"/>
     </textElement>
    <text><![CDATA[用户 id]]></text>
    </staticText>
      </cellContents>
     </crosstabHeaderCell>     <rowGroup

name="USER_ID_ATTE" width="70" totalPosition="End">
      <bucket>
       <bucketExpression class="java.math.BigDecimal"><![CDATA[$F

{USER_ID_ATTE}]]></bucketExpression>
      </bucket>
      <crosstabRowHeader>
      <cellContents backcolor="#F0F8FF" mode="Opaque">
     <box>     <pen lineWidth="0.5"

lineStyle="Solid" lineColor="#000000"/>
     <topPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
     <leftPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
     <bottomPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
     <rightPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
</box>
    <textField isStretchWithOverflow="false" isBlankWhenNull="false" evaluationTime="Now"

hyperlinkType="None"  hyperlinkTarget="Self" >
     <reportElement
      style="Crosstab Data Text"
      x="0"
      y="0"
      width="70"
      height="25"
      key="textField"/>
     <box></box>
     <textElement verticalAlignment="Middle">
      <font/>
     </textElement>
    <textFieldExpression   class="java.math.BigDecimal"><![CDATA[$V{USER_ID_ATTE}]]

></textFieldExpression>
    </textField>
      </cellContents>
      </crosstabRowHeader>
      <crosstabTotalRowHeader>
      <cellContents backcolor="#BFE1FF" mode="Opaque">
     <box>     <pen lineWidth="0.5"

lineStyle="Solid" lineColor="#000000"/>
     <topPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
     <leftPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
     <bottomPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
     <rightPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
</box>
    <staticText>
     <reportElement
      x="0"
      y="0"
      width="70"
      height="25"
      key="staticText"/>
     <box></box>
     <textElement textAlignment="Center" verticalAlignment="Middle">
      <font/>
     </textElement>
    <text><![CDATA[Total USER_ID_ATTE]]></text>
    </staticText>
      </cellContents>
      </crosstabTotalRowHeader>
     </rowGroup>
     <columnGroup name="ATTENDANCE_TIME" height="30" totalPosition="End"

headerPosition="Center">
      <bucket>
       <bucketExpression class="java.lang.String"><![CDATA[$F

{ATTENDANCE_TIME}]]></bucketExpression>
      </bucket>
      <crosstabColumnHeader>
      <cellContents backcolor="#F0F8FF" mode="Opaque">
     <box>     <pen lineWidth="0.5"

lineStyle="Solid" lineColor="#000000"/>
     <topPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
     <leftPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
     <bottomPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
     <rightPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
</box>
    <textField isStretchWithOverflow="false" isBlankWhenNull="false" evaluationTime="Now"

hyperlinkType="None"  hyperlinkTarget="Self" >
     <reportElement
      style="Crosstab Data Text"
      x="0"
      y="0"
      width="67"
      height="30"
      key="textField"/>
     <box></box>
     <textElement verticalAlignment="Middle">
      <font/>
     </textElement>
    <textFieldExpression   class="java.lang.String"><![CDATA[$V{ATTENDANCE_TIME}]]

></textFieldExpression>
    </textField>
      </cellContents>
      </crosstabColumnHeader>
      <crosstabTotalColumnHeader>
      <cellContents backcolor="#BFE1FF" mode="Opaque">
     <box>     <pen lineWidth="0.5"

lineStyle="Solid" lineColor="#000000"/>
     <topPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
     <leftPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
     <bottomPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
     <rightPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
</box>
    <staticText>
     <reportElement
      x="0"
      y="0"
      width="72"
      height="30"
      key="staticText"/>
     <box></box>
     <textElement textAlignment="Center" verticalAlignment="Middle">
      <font/>
     </textElement>
    <text><![CDATA[Total ]]></text>
    </staticText>
      </cellContents>
      </crosstabTotalColumnHeader>
     </columnGroup>

     <measure name="USER_ID_ATTEMeasure" class="java.math.BigDecimal"

calculation="Count">
      <measureExpression><![CDATA[$F{USER_ID_ATTE}]]

></measureExpression>
     </measure>
     <crosstabCell width="68" height="25">
      <cellContents mode="Transparent">
     <box>     <pen lineWidth="0.5"

lineStyle="Solid" lineColor="#000000"/>
     <topPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
     <leftPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
     <bottomPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
     <rightPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
</box>
    <textField isStretchWithOverflow="false" isBlankWhenNull="false" evaluationTime="Now"

hyperlinkType="None"  hyperlinkTarget="Self" >
     <reportElement
      style="Crosstab Data Text"
      x="0"
      y="0"
      width="67"
      height="25"
      key="textField"/>
     <box></box>
     <textElement verticalAlignment="Middle">
      <font/>
     </textElement>
    <textFieldExpression   class="java.math.BigDecimal"><![CDATA[$V

{USER_ID_ATTEMeasure}]]></textFieldExpression>
    </textField>
      </cellContents>
     </crosstabCell>
     <crosstabCell width="68" height="25" rowTotalGroup="USER_ID_ATTE">
      <cellContents backcolor="#BFE1FF" mode="Opaque">
     <box>     <pen lineWidth="0.5"

lineStyle="Solid" lineColor="#000000"/>
     <topPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
     <leftPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
     <bottomPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
     <rightPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
</box>
    <textField isStretchWithOverflow="false" isBlankWhenNull="false" evaluationTime="Now"

hyperlinkType="None"  hyperlinkTarget="Self" >
     <reportElement
      style="Crosstab Data Text"
      x="0"
      y="0"
      width="67"
      height="25"
      key="textField"/>
     <box></box>
     <textElement verticalAlignment="Middle">
      <font/>
     </textElement>
    <textFieldExpression   class="java.math.BigDecimal"><![CDATA[$V

{USER_ID_ATTEMeasure}]]></textFieldExpression>
    </textField>
      </cellContents>
     </crosstabCell>
     <crosstabCell width="73" height="25" columnTotalGroup="ATTENDANCE_TIME">
      <cellContents backcolor="#BFE1FF" mode="Opaque">
     <box>     <pen lineWidth="0.5"

lineStyle="Solid" lineColor="#000000"/>
     <topPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
     <leftPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
     <bottomPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
     <rightPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
</box>
    <textField isStretchWithOverflow="false" isBlankWhenNull="false" evaluationTime="Now"

hyperlinkType="None"  hyperlinkTarget="Self" >
     <reportElement
      style="Crosstab Data Text"
      x="0"
      y="0"
      width="72"
      height="25"
      key="textField"/>
     <box></box>
     <textElement verticalAlignment="Middle">
      <font/>
     </textElement>
    <textFieldExpression   class="java.math.BigDecimal"><![CDATA[$V

{USER_ID_ATTEMeasure}]]></textFieldExpression>
    </textField>
      </cellContents>
     </crosstabCell>
     <crosstabCell width="73" height="25" rowTotalGroup="USER_ID_ATTE"

columnTotalGroup="ATTENDANCE_TIME">
      <cellContents backcolor="#BFE1FF" mode="Opaque">
     <box>     <pen lineWidth="0.5"

lineStyle="Solid" lineColor="#000000"/>
     <topPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
     <leftPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
     <bottomPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
     <rightPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
</box>
    <textField isStretchWithOverflow="false" isBlankWhenNull="false" evaluationTime="Now"

hyperlinkType="None"  hyperlinkTarget="Self" >
     <reportElement
      style="Crosstab Data Text"
      x="0"
      y="0"
      width="72"
      height="25"
      key="textField"/>
     <box></box>
     <textElement verticalAlignment="Middle">
      <font/>
     </textElement>
    <textFieldExpression   class="java.math.BigDecimal"><![CDATA[$V

{USER_ID_ATTEMeasure}]]></textFieldExpression>
    </textField>
      </cellContents>
     </crosstabCell>
     <whenNoDataCell>      

<cellContents mode="Transparent">
     <box>     <pen lineWidth="0.5"

lineStyle="Solid" lineColor="#000000"/>
     <topPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
     <leftPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
     <bottomPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
     <rightPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
</box>
      </cellContents>
     </whenNoDataCell>     </crosstab>
   </band>
  </summary>
</jasperReport>

 

 

 

 

 

  • 0
    点赞
  • 0
    收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

zw7534313

你的鼓励将是我创作的最大动力

¥2 ¥4 ¥6 ¥10 ¥20
输入1-500的整数
余额支付 (余额:-- )
扫码支付
扫码支付:¥2
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值