我在地图中将两个日期设置为字符串,如下所示:
Map<String, String> hashmap = new HashMap<String, String>();
hashmap.put("date1", date1);
hashmap.put("date2", date2);
我正在使用如下:
JasperReport jasperReport1 = JasperCompileManager.compileReport(this.reportName1);
JasperPrint jasperPrint1 = JasperFillManager.fillReport(jasperReport1, hashmap, con);
jprintList.add(jasperPrint1);
1)如何在JRXML文件中使用此传递的参数。
基本上我在比较日期的两列,即第1列的第1列和第2列的第2列。
所以,我想在列标题中使用这些日期值。
<columnHeader>
<band height="11">
<rectangle>
<reportElement x="0" y="0" width="920" height="11" backcolor="#333333"/>
<graphicElement/>
</rectangle>
<staticText>
<reportElement mode="Opaque" x="20" y="0" width="80" height="11" forecolor="#ffffff" backcolor="#333333" style="Arial_Bold"/>
<textElement textAlignment="Left"/>
<text><![CDATA[Column for <here should come date1>]]></text>
</staticText>
<staticText>
<reportElement mode="Opaque" x="20" y="0" width="80" height="11" forecolor="#ffffff" backcolor="#333333" style="Arial_Bold"/>
<textElement textAlignment="Left"/>
<text><![CDATA[Column for <here should come date2>]]></text>
</staticText>
</columnHeader>
日期值将在“上面的代码中使用。
2)如何包装文本形成列标题?
我在excel中导出报告。
为了保持栏目标题的信息,我的标题是“显示12/12/2011日期价格的栏目” - 这很长,因为我总共有13列,每列都有这么长的标题。
如何在excel中包装文本或如何修复列标题的单元格大小。
我应该在JRXML中做些什么更改?
3)我在jprintlist中传递了几个报告。每个报告都将在最终的Excel文件中的单独工作表中发布。如何为工作表命名?默认情况下,它从标记中获取jasperReport的name属性,并在结尾添加1,2。
Ans:得到了答案
exporter.setParameter(JRXlsExporterParameter.SHEET_NAMES, new String[]{”Personal Information”, “Skills”});
感谢阅读!
答案 0 :(得分:1)
1)如何在JRXML文件中使用此传递的参数。
您可以使用 $P{}
表达式来使用参数。样本:
<text><![CDATA[Column for $P{date}]]></text>
2)如何包装文本形成列标题?
您可以使用 isStretchWithOverflow 和 stretchType 来增加标题。
样本:
<columnHeader>
<band height="20" splitType="Stretch">
<textField isStretchWithOverflow="true">
<reportElement stretchType="RelativeToTallestObject" x="0" y="0" width="100" height="20"/>
<box leftPadding="5">
<topPen lineWidth="1.0"/>
<leftPen lineWidth="1.0"/>
<bottomPen lineWidth="1.0"/>
<rightPen lineWidth="1.0"/>
</box>
<textElement/>
<textFieldExpression><![CDATA["Column for " + $P{title1}]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true">
<reportElement stretchType="RelativeToTallestObject" x="100" y="0" width="100" height="20"/>
<box leftPadding="5">
<topPen lineWidth="1.0"/>
<leftPen lineWidth="1.0"/>
<bottomPen lineWidth="1.0"/>
<rightPen lineWidth="1.0"/>
</box>
<textElement/>
<textFieldExpression><![CDATA["Column for " + $P{title2}]]></textFieldExpression>
</textField>
</band>
</columnHeader>
结果将是(Excel预览):
您还可以尝试为 textField 元素设置 net.sf.jasperreports.export.xls.wrap.text 属性。您可以阅读此属性here。
样本:
<textField>
<reportElement x="100" y="0" width="100" height="20">
<property name="net.sf.jasperreports.export.xls.wrap.text" value="false"/>
</reportElement>
<textElement/>
<textFieldExpression><![CDATA["Column for " + $P{title2}]]></textFieldExpression>
</textField>