2011-12-21 196 views
0

我设置两个日期作为字符串中的地图如下使用传递的参数:有关JRXML/Jasper报表的几个疑问 - 在Excel中固定单元尺寸,在JRXML

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的名称属性,并在末尾添加1,2。

答:得到这个问题的答案

exporter.setParameter(JRXlsExporterParameter.SHEET_NAMES, new String[]{”Personal Information”, “Skills”}); 

感谢您的阅读!

回答

1

1)如何在JRXML文件中使用这个参数。

您可以使用$P{}表达了使用的参数。样本:

<text><![CDATA[Column for $P{date}]]></text> 

2)如何自动换行形成列标题?

可以使用isStretchWithOverflowstretchType,让标题增长。

样本:

<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中预览):

enter image description here

您也可以尝试设置net.sf.jasperreports.export.xls。 wrap.text property for textField element。你可以阅读关于这个属性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> 
+0

@NikunjChauhan只需更新我的帖子 – 2011-12-21 13:17:42

+0

非常感谢!对于第一个查询,为了使答案完整,我们需要在我们的JRXML顶部声明参数,如: Nik 2011-12-21 13:32:39