iReport-使用不同日期的数据创建日历报告

时间:2018-07-12 03:02:11

标签: jasper-reports

最近,我在iReport中遇到了与日历报告有关的一些问题。 这是我用来创建日历的链接: Sample Report to Create a Monthly Calendar

使用上述参考,我创建了一个日历报告,可以显示与不同日期相对应的出勤记录:

<?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="CourtCaseSchedule" language="groovy" columnCount="7" pageWidth="2170" pageHeight="500" orientation="Landscape" whenNoDataType="AllSectionsNoDetail" columnWidth="310" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0" uuid="4bd402ec-2e5b-4f79-bfb6-69da329d8fe7">
    <property name="ireport.zoom" value="0.9090909090909121"/>
    <property name="ireport.x" value="0"/>
    <property name="ireport.y" value="0"/>
    <style name="style1">
        <conditionalStyle>
            <conditionExpression><![CDATA[$V{COLUMN_NUMBER} % 7 == 1]]></conditionExpression>
            <style forecolor="#FF3333" backcolor="#FFFFFF">
                <pen lineColor="#000000"/>
            </style>
        </conditionalStyle>
    </style>
    <style name="table">
        <box>
            <pen lineWidth="1.0" lineColor="#000000"/>
        </box>
    </style>
    <style name="table_TH" mode="Opaque" backcolor="#FFFFFF">
        <box>
            <pen lineWidth="0.5" lineColor="#000000"/>
        </box>
    </style>
    <style name="table_CH" mode="Opaque" backcolor="#FFBFBF">
        <box>
            <pen lineWidth="0.5" lineColor="#000000"/>
        </box>
    </style>
    <style name="table_TD" mode="Opaque" backcolor="#FFFFFF">
        <box>
            <pen lineWidth="0.5" lineColor="#000000"/>
        </box>
    </style>
    <subDataset name="Table Dataset 1" uuid="6d06249f-027b-4ca5-b2af-256229b56b96"/>
    <parameter name="REPORT_MONTH" class="java.lang.String"/>
    <parameter name="REPORT_YEAR" class="java.lang.String"/>
    <parameter name="srCCS_ReportDataSourceDetailsList" class="java.util.List"/>
    <parameter name="srCCS_JasperReportDetails" class="java.lang.String"/>
    <parameter name="SUBREPORT_DIR" class="java.lang.String" isForPrompting="false">
        <defaultValueExpression><![CDATA["C:\\Reports\\"]]></defaultValueExpression>
    </parameter>
    <field name="rCCSDayofWeek" class="java.lang.String"/>
    <field name="rCCSDate" class="java.lang.String"/>
    <variable name="SUBREPORT_INDEX" class="java.lang.Integer" incrementType="Column">
        <variableExpression><![CDATA[$F{rCCSDate}]]></variableExpression>
        <initialValueExpression><![CDATA[1]]></initialValueExpression>
    </variable>
    <title>
        <band height="75" splitType="Stretch">
            <staticText>
                <reportElement mode="Opaque" x="0" y="43" width="310" height="32" forecolor="#FFFFFF" backcolor="#FF3333" uuid="f86c7aa5-b2fa-4668-aaa4-3f3660d37655"/>
                <textElement textAlignment="Center" verticalAlignment="Middle">
                    <font size="22" isBold="true"/>
                </textElement>
                <text><![CDATA[Sunday]]></text>
            </staticText>
            <staticText>
                <reportElement mode="Opaque" x="310" y="43" width="310" height="32" forecolor="#FFFFFF" backcolor="#666666" uuid="fc91553f-de51-43f6-8cfa-fcf5d5dbbd2c"/>
                <textElement textAlignment="Center" verticalAlignment="Middle">
                    <font size="22" isBold="true"/>
                </textElement>
                <text><![CDATA[Monday]]></text>
            </staticText>
            <staticText>
                <reportElement mode="Opaque" x="620" y="43" width="310" height="32" forecolor="#FFFFFF" backcolor="#666666" uuid="487a8ddb-6029-4c65-8a40-afabdb55d613"/>
                <textElement textAlignment="Center" verticalAlignment="Middle">
                    <font size="22" isBold="true"/>
                </textElement>
                <text><![CDATA[Tuesday]]></text>
            </staticText>
            <staticText>
                <reportElement mode="Opaque" x="930" y="43" width="310" height="32" forecolor="#FFFFFF" backcolor="#666666" uuid="c9a33cdb-66de-47a7-a350-d2a7672ec3ce"/>
                <textElement textAlignment="Center" verticalAlignment="Middle">
                    <font size="22" isBold="true"/>
                </textElement>
                <text><![CDATA[Wednesday]]></text>
            </staticText>
            <staticText>
                <reportElement mode="Opaque" x="1240" y="43" width="310" height="32" forecolor="#FFFFFF" backcolor="#666666" uuid="0555ba56-fd4c-4f02-b0a2-c51945547af4"/>
                <textElement textAlignment="Center" verticalAlignment="Middle">
                    <font size="22" isBold="true"/>
                </textElement>
                <text><![CDATA[Thursday]]></text>
            </staticText>
            <staticText>
                <reportElement mode="Opaque" x="1550" y="43" width="310" height="32" forecolor="#FFFFFF" backcolor="#666666" uuid="62afe59e-0dda-4b68-89d0-5e3bc6dbf1f8"/>
                <textElement textAlignment="Center" verticalAlignment="Middle">
                    <font size="22" isBold="true"/>
                </textElement>
                <text><![CDATA[Friday]]></text>
            </staticText>
            <staticText>
                <reportElement mode="Opaque" x="1860" y="43" width="310" height="32" forecolor="#FFFFFF" backcolor="#666666" uuid="56f14a13-3fe0-41c2-827b-8cbce1234467"/>
                <textElement textAlignment="Center" verticalAlignment="Middle">
                    <font size="22" isBold="true"/>
                </textElement>
                <text><![CDATA[Saturday]]></text>
            </staticText>
            <textField>
                <reportElement x="0" y="0" width="2170" height="43" uuid="2772960e-b50a-4f5f-a80a-56aa8e28891a"/>
                <textElement textAlignment="Center" verticalAlignment="Middle">
                    <font size="32" isBold="true"/>
                </textElement>
                <textFieldExpression><![CDATA["Court Case Schedule of " + $P{REPORT_MONTH} + " " + $P{REPORT_YEAR}]]></textFieldExpression>
            </textField>
        </band>
    </title>
    <detail>
        <band height="300" splitType="Stretch">
            <frame>
                <reportElement stretchType="RelativeToBandHeight" x="0" y="0" width="310" height="300" uuid="cd88766b-0047-4150-b29c-2e7227fbb00c"/>
                <textField>
                    <reportElement style="style1" positionType="Float" mode="Transparent" x="0" y="0" width="68" height="58" uuid="293e7d8e-d54f-4776-9311-7d9f0270d573">
                        <printWhenExpression><![CDATA[$F{rCCSDayofWeek}.isEmpty() || $F{rCCSDayofWeek}.equals(java.lang.Integer.toString($V{COLUMN_NUMBER}))]]></printWhenExpression>
                    </reportElement>
                    <textElement verticalAlignment="Middle">
                        <font size="28" isBold="true"/>
                        <paragraph leftIndent="3"/>
                    </textElement>
                    <textFieldExpression><![CDATA[$F{rCCSDate}]]></textFieldExpression>
                </textField>
                <subreport>
                    <reportElement positionType="Float" stretchType="RelativeToTallestObject" x="0" y="58" width="310" height="242" uuid="f8fcd85a-d8cf-4b88-b563-652f6d13351d"/>
                    <dataSourceExpression><![CDATA[$P{srCCS_ReportDataSourceDetailsList}.get($V{REPORT_COUNT}-1)]]></dataSourceExpression>
                    <subreportExpression><![CDATA[$P{SUBREPORT_DIR} + "CourtCaseSchedule_SubReport.jasper"]]></subreportExpression>
                </subreport>
            </frame>
        </band>
    </detail>
</jasperReport>

此报告仅生成一个每月日历,每个单元格中都有一个子报告,该子报告会根据每个日期显示出勤信息。

现在的问题是,在主报表的页面高度固定的情况下,当子报表中的行太多并且其高度溢出主报表的页面高度时,它将自动切换到报表的下一列。结果,该报告将格式错误。我一直在寻找各种解决溢出问题的方法,但是没有一个起作用。有人可以启发我解决此问题吗?

以下是我尝试过的Jasper中可用的一些属性:

  • 位置类型:浮动
  • 报告拆分类型:拉伸
  • row的报表元素中包含columnnet.sf.jasperreports.export.xls.auto.fit属性
  • 在运行时设置明细带高度

1 个答案:

答案 0 :(得分:0)

最后,我拒绝了Jasperreports,我设法将实现切换到poi。在这种情况下,根据我的需要,Excel配置可能会更加灵活。

结论:Jasper不能创建包含日历的内容!