如何合并同一列中的单元格,应用rowspan? [英] How to merge cells in same column, apply rowspan?
问题描述
在我的报告的jrxml设计中,我的详细信息部分中有一列为特定组打印相同的内容。例如,如果我有一个国家列美国,下一列包含其状态。美国国家/地区重复每个条目。所以我需要合并国家细胞有美国价值。我需要合并列的所有单元格具有相同的值,并应将其显示为单个单元格,并且应将其文本垂直和水平对齐。任何人帮助我如何通过使用jrxml来实现这一目标?
In jrxml design for my report, I have a column in my detail section that is printing same thing for a specific group. For Example, if i have a country column USA and the next column contains its states. Country USA repeats for each entry . So i need to merge the country cells has USA value. I need to merge all the cells of column has same value and should display it as a single cell and it should align its text vertically and horizontally center. Anybody help me how can i achieve this by using jrxml?
一切都在细节范围内。
I我正在努力获得如下图所示的报告
I am working to get a report like in the below picture
更新:
从彼得的回答中我有一个疑问,如果我的xml是喜欢:
From Peter's answer I have one doubt, if my xml is like:
<report>
<row1>
<country>INDIA</country>
<state>Haryana</state>
</row1>
<row2>
<country>INDIA</country>
<state>Punjab</state>
</row2>
<row3>
<country>INDIA</country>
<state>Maharashtra</state>
</row3>
</report>
如果我的xml如上所述,如何创建报告?
How can I create the report if my xml is like above?
推荐答案
您可以通过 isPrintRepeatedValues =false$轻松实现垂直对齐的文字 c $ c>,正确设置边框(仅限顶部,使用仅剩下的空单元格,将行添加到
columnFooter
)。
You can fairly easy achieve text vertically aligned at top by using isPrintRepeatedValues="false"
, setting borders correctly (only top, using empty cell with only left, adding line to columnFooter
).
要实现文本在中心垂直对齐,请使用子报告您的rowspan列上的列和设置 stretchType =RelativeToBandHeight
。
To achieve "text vertically aligned at center" use a subreport for the other columns and set stretchType="RelativeToBandHeight"
on your rowspan column.
请注意,在这种情况下您需要更改数据源(主报告,按国家/地区,子报告所有州相对于国家/地区)
Note you need in this case change your datasource (main report, country by country, subreport all states relative to country)
编辑:评论:这不适用于详细的乐队。 Petter - @Tinoy Malayil 。
我在中心垂直对齐的文本中包含一个可运行的示例:
I include a runnable example for text vertically aligned at center:
数据源 xml:
<report>
<country>
<name>INDIA</name>
<states>
<state>Haryana</state>
<state>Punjab</state>
<state>Maharashtra</state>
<state>Karnataka</state>
<state>TamilNadu</state>
</states>
</country>
<country>
<name>USA</name>
<states>
<state>Alabama</state>
<state>Washington</state>
<state>Alaska</state>
<state>Texas</state>
</states>
</country>
</report>
主要报告:, country.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="Country" pageWidth="595" pageHeight="842" whenNoDataType="AllSectionsNoDetail" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="30" bottomMargin="30" uuid="dbc44bea-4f8e-4072-9c94-8442f3093aa0">
<parameter name="SUBREPORT_DIR" class="java.lang.String" isForPrompting="false">
<defaultValueExpression><![CDATA["C:\\fullPath\\to\\Your\\subreport\\"]]></defaultValueExpression>
</parameter>
<queryString language="xPath">
<![CDATA[report/country]]>
</queryString>
<field name="name" class="java.lang.String">
<fieldDescription><![CDATA[name]]></fieldDescription>
</field>
<background>
<band/>
</background>
<columnHeader>
<band height="20">
<staticText>
<reportElement x="0" y="0" width="177" height="20" uuid="d4eb7868-2f74-4713-abca-a176c47927e1"/>
<box>
<pen lineWidth="0.25"/>
<topPen lineWidth="0.25"/>
<leftPen lineWidth="0.25"/>
<bottomPen lineWidth="0.25"/>
<rightPen lineWidth="0.25"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<text><![CDATA[COUNTRY]]></text>
</staticText>
<staticText>
<reportElement x="177" y="0" width="200" height="20" uuid="98cbcff7-6b24-43bd-a2df-39cc07e56487"/>
<box>
<pen lineWidth="0.25"/>
<topPen lineWidth="0.25"/>
<leftPen lineWidth="0.25"/>
<bottomPen lineWidth="0.25"/>
<rightPen lineWidth="0.25"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<text><![CDATA[STATE]]></text>
</staticText>
</band>
</columnHeader>
<detail>
<band height="20">
<textField>
<reportElement stretchType="RelativeToBandHeight" x="0" y="0" width="177" height="20" uuid="1bbab3e7-f8a3-48c9-b28e-2a6d2a68b755"/>
<box topPadding="0" leftPadding="0">
<pen lineWidth="0.25"/>
<topPen lineWidth="0.25"/>
<leftPen lineWidth="0.25"/>
<bottomPen lineWidth="0.25"/>
<rightPen lineWidth="0.25"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<textFieldExpression><![CDATA[$F{name}]]></textFieldExpression>
</textField>
<subreport>
<reportElement x="177" y="0" width="200" height="20" uuid="6314908a-006d-4a5b-9137-a056eb205529"/>
<dataSourceExpression><![CDATA[((net.sf.jasperreports.engine.data.JRXmlDataSource)$P{REPORT_DATA_SOURCE}).subDataSource("/country/states/state")]]></dataSourceExpression>
<subreportExpression><![CDATA[$P{SUBREPORT_DIR} + "country_subreport.jasper"]]></subreportExpression>
</subreport>
</band>
</detail>
</jasperReport>
子报告, country_subreport.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="country_subreport" language="java" pageWidth="200" pageHeight="500" columnWidth="200" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0" uuid="c9795fb7-39e0-4aa6-8926-2f019c4af84e">
<property name="ireport.zoom" value="1.0"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<queryString language="xPath">
<![CDATA[/report/country/states/state]]>
</queryString>
<field name="state" class="java.lang.String">
<fieldDescription><![CDATA[child::text()]]></fieldDescription>
</field>
<detail>
<band height="20" splitType="Stretch">
<textField>
<reportElement x="0" y="0" width="200" height="20" uuid="dc0a9dda-b940-4752-ad91-31420c4ce729"/>
<box topPadding="2" leftPadding="2">
<pen lineWidth="0.25"/>
<topPen lineWidth="0.25"/>
<leftPen lineWidth="0.25"/>
<bottomPen lineWidth="0.25"/>
<rightPen lineWidth="0.25"/>
</box>
<textElement verticalAlignment="Middle"/>
<textFieldExpression><![CDATA[$F{state}]]></textFieldExpression>
</textField>
</band>
</detail>
这篇关于如何合并同一列中的单元格,应用rowspan?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!