简体   繁体   English

JasperReports / iReport中的Excel数据源:无法获取类'java.sql.Date'的字段'Date'的值

[英]Excel datasource in JasperReports/iReport: Unable to get value for field 'Date' of class 'java.sql.Date'

I've used an Excel file as datasource for building report with iReport . 我使用Excel文件作为数据源来使用iReport构建报表。 The xls file contains dates yyyy-MM-dd format. xls文件包含日期yyyy-MM-dd格式。

I've set the Date field class to java.sql.Date and I click on preview in iReport . 我已将Date字段类设置为java.sql.Date ,然后单击iReport中的预览。 There is an error: Unable to get value for field 'Date' of class 'java.sql.Date'. 有一个错误: Unable to get value for field 'Date' of class 'java.sql.Date'.

I have tried with java.util.Date too. 我也尝试过java.util.Date Do you have any ideas? 你有什么想法?

It is quite simple. 这很简单。

I've xls file ( birhdays.xls ) like this: 我有这样的xls文件( birhdays.xls ):

在此输入图像描述

The datasource definition (in iReport ) is: 数据源定义(在iReport中 )是:

在此输入图像描述

As you can see from the image above I've set yyyy-MM-dd format for date field in DS definition. 从上图中可以看出,我在DS定义中为日期字段设置了yyyy-MM-dd格式。

The date field definition in jrxml file: jrxml文件中的日期字段定义:

<field name="Birthday" class="java.util.Date"/>

The full jrxml file: 完整的jrxml文件:

<?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="excel_ds" language="groovy" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="b0f82d57-325b-4c30-b635-f464851e0a47">
    <queryString>
        <![CDATA[]]>
    </queryString>
    <field name="Name" class="java.lang.String"/>
    <field name="Birthday" class="java.util.Date"/>
    <columnHeader>
        <band height="20" splitType="Stretch">
            <staticText>
                <reportElement uuid="cd75f6d9-1781-4938-bf24-178b6663bcd1" x="0" y="0" width="147" height="20"/>
                <box leftPadding="10">
                    <topPen lineWidth="1.0"/>
                    <leftPen lineWidth="1.0"/>
                    <bottomPen lineWidth="1.0"/>
                    <rightPen lineWidth="1.0"/>
                </box>
                <textElement textAlignment="Center" verticalAlignment="Middle">
                    <font isBold="true" isItalic="true"/>
                </textElement>
                <text><![CDATA[Name]]></text>
            </staticText>
            <staticText>
                <reportElement uuid="5d4c21f1-9afd-40c7-ade0-6fcc0b3d8373" x="147" y="0" width="100" height="20"/>
                <box leftPadding="10">
                    <topPen lineWidth="1.0"/>
                    <leftPen lineWidth="1.0"/>
                    <bottomPen lineWidth="1.0"/>
                    <rightPen lineWidth="1.0"/>
                </box>
                <textElement textAlignment="Center" verticalAlignment="Middle">
                    <font isBold="true" isItalic="true"/>
                </textElement>
                <text><![CDATA[Birthday]]></text>
            </staticText>
        </band>
    </columnHeader>
    <detail>
        <band height="20" splitType="Stretch">
            <textField>
                <reportElement uuid="82f5a338-ef5d-4838-8cd0-c2544af3a73d" x="0" y="0" width="147" height="20"/>
                <box leftPadding="10">
                    <topPen lineWidth="1.0"/>
                    <leftPen lineWidth="1.0"/>
                    <bottomPen lineWidth="1.0"/>
                    <rightPen lineWidth="1.0"/>
                </box>
                <textElement/>
                <textFieldExpression><![CDATA[$F{Name}]]></textFieldExpression>
            </textField>
            <textField pattern="dd/MM/yyyy">
                <reportElement uuid="e6eb6f83-b8f3-42fd-b116-02db2322b6a5" x="147" y="0" width="100" height="20"/>
                <box leftPadding="10">
                    <topPen lineWidth="1.0"/>
                    <leftPen lineWidth="1.0"/>
                    <bottomPen lineWidth="1.0"/>
                    <rightPen lineWidth="1.0"/>
                </box>
                <textElement/>
                <textFieldExpression><![CDATA[$F{Birthday}]]></textFieldExpression>
            </textField>
        </band>
    </detail>
</jasperReport>

And the result will be (via preview in iReport ): 结果将是(通过iReport中的预览):

在此输入图像描述

Note : 注意

I've used iReport 5.1.0 我用过iReport 5.1.0

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM