大家好, 我在我的列带中使用静态文本元素。在该元素中,我将文本垂直对齐在元素的中心。当我导出jrxml文件时,我需要在excel文件中使用相同的对齐方式。但是我得到默认的水平对齐..请给我解决方案
答案 0 :(得分:2)
您可以尝试以下示例:
<?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="test_excel_columns" language="groovy" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20">
<property name="ireport.zoom" value="1.0"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<queryString>
<![CDATA[SELECT ID, FIRSTNAME, LASTNAME, STREET, CITY FROM ADDRESS]]>
</queryString>
<field name="ID" class="java.lang.Integer"/>
<field name="FIRSTNAME" class="java.lang.String"/>
<field name="LASTNAME" class="java.lang.String"/>
<field name="STREET" class="java.lang.String"/>
<field name="CITY" class="java.lang.String"/>
<columnHeader>
<band height="35" splitType="Stretch">
<staticText>
<reportElement x="0" y="0" width="75" height="35"/>
<box>
<topPen lineWidth="1.0"/>
<leftPen lineWidth="1.0"/>
<bottomPen lineWidth="1.0"/>
<rightPen lineWidth="1.0"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<text><![CDATA[ID]]></text>
</staticText>
<staticText>
<reportElement x="75" y="0" width="271" height="35"/>
<box>
<topPen lineWidth="1.0"/>
<leftPen lineWidth="0.0"/>
<bottomPen lineWidth="1.0"/>
<rightPen lineWidth="1.0"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<text><![CDATA[Name]]></text>
</staticText>
<staticText>
<reportElement x="346" y="0" width="100" height="35"/>
<box>
<topPen lineWidth="1.0"/>
<leftPen lineWidth="0.0"/>
<bottomPen lineWidth="1.0"/>
<rightPen lineWidth="1.0"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<text><![CDATA[Street]]></text>
</staticText>
<staticText>
<reportElement x="446" y="0" width="100" height="35"/>
<box>
<topPen lineWidth="1.0"/>
<leftPen lineWidth="0.0"/>
<bottomPen lineWidth="1.0"/>
<rightPen lineWidth="1.0"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<text><![CDATA[City]]></text>
</staticText>
</band>
</columnHeader>
<detail>
<band height="20" splitType="Stretch">
<textField>
<reportElement x="0" y="0" width="75" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$F{ID}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="75" y="0" width="271" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$F{FIRSTNAME} + " " + $F{LASTNAME}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="346" y="0" width="100" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$F{STREET}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="446" y="0" width="100" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$F{CITY}]]></textFieldExpression>
</textField>
</band>
</detail>
</jasperReport>
Excel预览中的输出为:
我的 iReport
版本为4.1.3
。