我有一个交叉表,我需要根据国家/地区的区域设置显示日期和数字。我理解我需要使用文本表达式,但我无法确定如何使用参数。该地区以“en-IN'(印度)”,“de-DE”(德国)等形式出现在所有国家/地区。日期和数字格式必须根据登录的人员的区域设置进行更改
我已经能够在参数中获取用户区域设置。但是,我不知道如何在交叉表中使用它。
PFB jrxml。我一直收到错误表达式ID
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.1.0.final using JasperReports Library version 6.1.0 -->
<!-- 2016-11-04T12:23:19 -->
<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="crosstabmeasure" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="e47b3f7d-1e00-4702-a900-be50a229f085">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="mysql251"/>
<import value="org.apache.commons.lang3.time.*"/>
<style name="Crosstab_CH" mode="Opaque" backcolor="#F0F8FF">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
<topPen lineWidth="0.5" lineColor="#000000"/>
<leftPen lineWidth="0.5" lineColor="#000000"/>
<bottomPen lineWidth="0.5" lineColor="#000000"/>
<rightPen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<style name="Crosstab_CG" mode="Opaque" backcolor="#BFE1FF">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
<topPen lineWidth="0.5" lineColor="#000000"/>
<leftPen lineWidth="0.5" lineColor="#000000"/>
<bottomPen lineWidth="0.5" lineColor="#000000"/>
<rightPen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<style name="Crosstab_CT" mode="Opaque" backcolor="#005FB3">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
<topPen lineWidth="0.5" lineColor="#000000"/>
<leftPen lineWidth="0.5" lineColor="#000000"/>
<bottomPen lineWidth="0.5" lineColor="#000000"/>
<rightPen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<style name="Crosstab_CD" mode="Opaque" backcolor="#FFFFFF">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
<topPen lineWidth="0.5" lineColor="#000000"/>
<leftPen lineWidth="0.5" lineColor="#000000"/>
<bottomPen lineWidth="0.5" lineColor="#000000"/>
<rightPen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<subDataset name="set1" uuid="0271cb46-f184-47b2-8ab3-e6ee96ea33ef">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="mysql251"/>
<parameter name="Locale" class="java.lang.String">
<defaultValueExpression><![CDATA["en-IN"]]></defaultValueExpression>
</parameter>
<parameter name="UtcOffSet" class="java.lang.Integer">
<defaultValueExpression><![CDATA[330]]></defaultValueExpression>
</parameter>
<queryString>
<![CDATA[select * from internatioinlization]]>
</queryString>
<field name="col1" class="java.lang.String">
<fieldDescription><![CDATA[]]></fieldDescription>
</field>
<field name="col2" class="java.lang.Integer">
<fieldDescription><![CDATA[]]></fieldDescription>
</field>
<field name="col3" class="java.sql.Timestamp">
<fieldDescription><![CDATA[]]></fieldDescription>
</field>
<field name="col4" class="java.lang.String">
<fieldDescription><![CDATA[]]></fieldDescription>
</field>
</subDataset>
<parameter name="Locale" class="java.lang.String">
<defaultValueExpression><![CDATA["en-IN"]]></defaultValueExpression>
</parameter>
<parameter name="UtcOffSet" class="java.lang.Integer">
<defaultValueExpression><![CDATA["fi-FI"]]></defaultValueExpression>
</parameter>
<queryString>
<![CDATA[select * from internatioinlization]]>
</queryString>
<field name="col1" class="java.lang.String">
<fieldDescription><![CDATA[]]></fieldDescription>
</field>
<field name="col2" class="java.lang.Integer">
<fieldDescription><![CDATA[]]></fieldDescription>
</field>
<field name="col3" class="java.sql.Timestamp">
<fieldDescription><![CDATA[]]></fieldDescription>
</field>
<field name="col4" class="java.lang.String">
<fieldDescription><![CDATA[]]></fieldDescription>
</field>
<background>
<band splitType="Stretch"/>
</background>
<summary>
<band height="211" splitType="Stretch">
<crosstab>
<reportElement x="0" y="0" width="555" height="211" uuid="6c5ccb8a-50fc-4158-b2ba-88d864aa1e43"/>
<crosstabParameter name="Parameter1"/>
<crosstabParameter name="Parameter2" class="java.lang.Integer"/>
<crosstabDataset>
<dataset>
<datasetRun subDataset="set1" uuid="d255c9b9-fbb2-420a-8ef5-3236098654f1">
<datasetParameter name="Locale">
<datasetParameterExpression><![CDATA[$P{Locale}]]></datasetParameterExpression>
</datasetParameter>
<datasetParameter name="UtcOffSet">
<datasetParameterExpression><![CDATA[$P{UtcOffSet}]]></datasetParameterExpression>
</datasetParameter>
<connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
</datasetRun>
</dataset>
</crosstabDataset>
<rowGroup name="col11" width="60">
<bucket class="java.lang.String">
<bucketExpression><![CDATA[$F{col1}]]></bucketExpression>
</bucket>
<crosstabRowHeader>
<cellContents mode="Opaque" style="Crosstab_CH">
<textField>
<reportElement x="0" y="0" width="60" height="20" uuid="86c09a7f-46b5-4d2f-ba87-715f99d832a8"/>
<textFieldExpression><![CDATA[$V{col11}]]></textFieldExpression>
</textField>
</cellContents>
</crosstabRowHeader>
<crosstabTotalRowHeader>
<cellContents>
<staticText>
<reportElement x="0" y="0" width="-2147483648" height="-2147483648" uuid="94fca0ea-1572-4d42-85d9-b06f92c73b6e"/>
<text><![CDATA[Total col11]]></text>
</staticText>
</cellContents>
</crosstabTotalRowHeader>
</rowGroup>
<columnGroup name="col41" height="20">
<bucket class="java.lang.String">
<bucketExpression><![CDATA[$F{col4}]]></bucketExpression>
</bucket>
<crosstabColumnHeader>
<cellContents mode="Opaque" style="Crosstab_CH">
<property name="com.jaspersoft.studio.unit.width" value="pixel"/>
<textField>
<reportElement x="0" y="0" width="120" height="20" uuid="137ef406-6a2e-4629-9d38-4858c4a5ae2c">
<property name="com.jaspersoft.studio.unit.width" value="pixel"/>
</reportElement>
<textFieldExpression><![CDATA[$V{col41}]]></textFieldExpression>
</textField>
</cellContents>
</crosstabColumnHeader>
<crosstabTotalColumnHeader>
<cellContents>
<staticText>
<reportElement x="0" y="0" width="-2147483648" height="-2147483648" uuid="5c71211d-f1db-4911-8923-2bdb208ddb99"/>
<text><![CDATA[Total col41]]></text>
</staticText>
</cellContents>
</crosstabTotalColumnHeader>
</columnGroup>
<measure name="col2_MEASURE1" class="java.lang.Integer">
<measureExpression><![CDATA[$F{col2}]]></measureExpression>
</measure>
<measure name="col3_MEASURE1" class="java.util.Date">
<measureExpression><![CDATA[$F{col3}]]></measureExpression>
</measure>
<crosstabCell width="120" height="20">
<cellContents mode="Opaque" style="Crosstab_CD">
<textField>
<reportElement x="0" y="0" width="60" height="20" uuid="861d0d3a-d774-4b0c-ae7d-ace315bf305c"/>
<textFieldExpression><![CDATA[$V{col2_MEASURE1}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="60" y="0" width="60" height="20" uuid="163ed502-e753-444a-942d-832d84da0a5f">
<property name="com.jaspersoft.studio.unit.y" value="pixel"/>
<property name="com.jaspersoft.studio.unit.x" value="pixel"/>
<property name="com.jaspersoft.studio.unit.height" value="pixel"/>
</reportElement>
<textFieldExpression><![CDATA[$V{col3_MEASURE1} != null ? DateFormat.getDateInstance(DateFormat.SHORT, new Locale($P{Parameter1}.split("-")[0], $P{Parameter1}.split("-")[1])).format(DateUtils.addMinutes($V{col3_MEASURE1},$P{Parameter2})) : null]]></textFieldExpression>
</textField>
</cellContents>
</crosstabCell>
<crosstabCell width="60" height="20" columnTotalGroup="col41">
<cellContents mode="Opaque" style="Crosstab_CT">
<textField>
<reportElement x="0" y="0" width="60" height="10" forecolor="#FFFFFF" uuid="2576b9e2-3bba-40e3-aa15-5f4f0aada549"/>
<textFieldExpression><![CDATA[$V{col2_MEASURE1}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="0" y="10" width="60" height="10" forecolor="#FFFFFF" uuid="a111181f-b60f-4afd-8292-9e260c1b9ce2"/>
<textFieldExpression><![CDATA[$V{col3_MEASURE1}]]></textFieldExpression>
</textField>
</cellContents>
</crosstabCell>
<crosstabCell width="60" height="20" rowTotalGroup="col11">
<cellContents mode="Opaque" style="Crosstab_CT">
<textField>
<reportElement x="0" y="0" width="60" height="10" forecolor="#FFFFFF" uuid="9adf6c9c-acee-4673-8b70-a376e7d1cbb4"/>
<textFieldExpression><![CDATA[$V{col2_MEASURE1}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="0" y="10" width="60" height="10" forecolor="#FFFFFF" uuid="9baedeed-4770-4153-b639-afc0965e9467"/>
<textFieldExpression><![CDATA[$V{col3_MEASURE1}]]></textFieldExpression>
</textField>
</cellContents>
</crosstabCell>
<crosstabCell width="60" height="20" rowTotalGroup="col11" columnTotalGroup="col41">
<cellContents mode="Opaque" style="Crosstab_CT">
<textField>
<reportElement x="0" y="0" width="60" height="10" forecolor="#FFFFFF" uuid="a2805e0a-080d-42be-ad86-a7e8e666f571"/>
<textFieldExpression><![CDATA[$V{col2_MEASURE1}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="0" y="10" width="60" height="10" forecolor="#FFFFFF" uuid="c485f69d-91e1-4b19-a8ab-bdbfa3cafcc6"/>
<textFieldExpression><![CDATA[$V{col3_MEASURE1}]]></textFieldExpression>
</textField>
</cellContents>
</crosstabCell>
</crosstab>
</band>
</summary>
</jasperReport>
提前致谢 瑞斯
答案 0 :(得分:0)
嗯,这实际上是一个奇怪的问题,因为通常日期和数字格式都是由Java引擎完成的。
您可以创建资源包并向其添加pattern.date = DD.MM.YYYY
。
在日期文本字段中,只需将模式表达式更改为$R{pattern.date}
,即可开始使用。