jasperreports-server中的示例报表是怎么制作的
1个回答
展开全部
下面的代码(JasperReportExport.java)演示了JasperReport文档的导出过程。该JasperExportManager提供的方法将报表导出成PDF,HTML和XML。导出到使用的类net.sf.jasperreports.engine.export.JRXlsExporter的XLS格式。此代码生成以下三个文件:
· sample_report.pdf
· sample_report.htmll
· sample_report.xls
导出为其他格式
让我们来写一个报表模板。在JRXML文件的内容 (C:\tools\jasperreports-5.0.1\test\jasper_report_template.jrxml) 如下:
<queryString>
<![CDATA[]]>
</queryString>
<fieldname="country"class="java.lang.String">
<fieldDescription><![CDATA[country]]></fieldDescription>
</field>
<fieldname="name"class="java.lang.String">
<fieldDescription><![CDATA[name]]></fieldDescription>
</field>
<columnHeader>
<bandheight="23">
<staticText>
<reportElementmode="Opaque"x="0"y="3"width="535"
height="15"backcolor="#70A9A9"/>
<box>
<bottomPenlineWidth="1.0"lineColor="#CCCCCC"/>
</box>
<textElement/>
<text><![CDATA[]]> </text>
</staticText>
<staticText>
<reportElementx="414"y="3"width="121"height="15"/>
<textElementtextAlignment="Center"
verticalAlignment="Middle">
<fontisBold="true"/>
</textElement>
<text><![CDATA[Country]]></text>
</staticText>
<staticText>
<reportElementx="0"y="3"width="136"height="15"/>
<textElementtextAlignment="Center"
verticalAlignment="Middle">
<fontisBold="true"/>
</textElement>
<text><![CDATA[Name]]></text>
</staticText>
</band>
</columnHeader>
<detail>
<bandheight="16">
<staticText>
<reportElementmode="Opaque"x="0"y="0"width="535"
height="14"backcolor="#E5ECF9"/>
<box>
<bottomPenlineWidth="0.25"lineColor="#CCCCCC"/>
</box>
<textElement/>
<text><![CDATA[]]> </text>
</staticText>
<textField>
<reportElementx="414"y="0"width="121"height="15"/>
<textElementtextAlignment="Center"
verticalAlignment="Middle">
<fontsize="9"/>
</textElement>
<textFieldExpressionclass="java.lang.String">
<![CDATA[$F{country}]]>
</textFieldExpression>
</textField>
<textField>
<reportElementx="0"y="0"width="136"height="15"/>
<textElementtextAlignment="Center"
verticalAlignment="Middle"/>
<textFieldExpressionclass="java.lang.String">
<![CDATA[$F{name}]]>
</textFieldExpression>
</textField>
</band>
</detail>
</jasperReport>
问件C:\tools\jasperreports-5.0.1\test\src\com\yiibai\DataBeanList.java 的内容如下:
package com.yiibai;
import java.util.ArrayList;
publicclassDataBeanList{
publicArrayList<DataBean> getDataBeanList(){
ArrayList<DataBean> dataBeanList =newArrayList<DataBean>();
dataBeanList.add(produce("Manisha","India"));
dataBeanList.add(produce("Dennis Ritchie","USA"));
dataBeanList.add(produce("V.Anand","India"));
dataBeanList.add(produce("Shrinath","California"));
return dataBeanList;
}
· sample_report.pdf
· sample_report.htmll
· sample_report.xls
导出为其他格式
让我们来写一个报表模板。在JRXML文件的内容 (C:\tools\jasperreports-5.0.1\test\jasper_report_template.jrxml) 如下:
<queryString>
<![CDATA[]]>
</queryString>
<fieldname="country"class="java.lang.String">
<fieldDescription><![CDATA[country]]></fieldDescription>
</field>
<fieldname="name"class="java.lang.String">
<fieldDescription><![CDATA[name]]></fieldDescription>
</field>
<columnHeader>
<bandheight="23">
<staticText>
<reportElementmode="Opaque"x="0"y="3"width="535"
height="15"backcolor="#70A9A9"/>
<box>
<bottomPenlineWidth="1.0"lineColor="#CCCCCC"/>
</box>
<textElement/>
<text><![CDATA[]]> </text>
</staticText>
<staticText>
<reportElementx="414"y="3"width="121"height="15"/>
<textElementtextAlignment="Center"
verticalAlignment="Middle">
<fontisBold="true"/>
</textElement>
<text><![CDATA[Country]]></text>
</staticText>
<staticText>
<reportElementx="0"y="3"width="136"height="15"/>
<textElementtextAlignment="Center"
verticalAlignment="Middle">
<fontisBold="true"/>
</textElement>
<text><![CDATA[Name]]></text>
</staticText>
</band>
</columnHeader>
<detail>
<bandheight="16">
<staticText>
<reportElementmode="Opaque"x="0"y="0"width="535"
height="14"backcolor="#E5ECF9"/>
<box>
<bottomPenlineWidth="0.25"lineColor="#CCCCCC"/>
</box>
<textElement/>
<text><![CDATA[]]> </text>
</staticText>
<textField>
<reportElementx="414"y="0"width="121"height="15"/>
<textElementtextAlignment="Center"
verticalAlignment="Middle">
<fontsize="9"/>
</textElement>
<textFieldExpressionclass="java.lang.String">
<![CDATA[$F{country}]]>
</textFieldExpression>
</textField>
<textField>
<reportElementx="0"y="0"width="136"height="15"/>
<textElementtextAlignment="Center"
verticalAlignment="Middle"/>
<textFieldExpressionclass="java.lang.String">
<![CDATA[$F{name}]]>
</textFieldExpression>
</textField>
</band>
</detail>
</jasperReport>
问件C:\tools\jasperreports-5.0.1\test\src\com\yiibai\DataBeanList.java 的内容如下:
package com.yiibai;
import java.util.ArrayList;
publicclassDataBeanList{
publicArrayList<DataBean> getDataBeanList(){
ArrayList<DataBean> dataBeanList =newArrayList<DataBean>();
dataBeanList.add(produce("Manisha","India"));
dataBeanList.add(produce("Dennis Ritchie","USA"));
dataBeanList.add(produce("V.Anand","India"));
dataBeanList.add(produce("Shrinath","California"));
return dataBeanList;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询