jasperReport+ireport实现报表导出和数据分析

jasperReport + ireport组合实现报表文件(各种文件格式xsl.pdf,rtf等)的生成导出是目前开源报表中使用的最为广泛的。在平台一期完成之后,而且功能中报表以及数据分析这块是必不可少的,一下展示如何使用JasperReport + ireport导出excel报表。

1.需要.jasper文件作为生成报表的模板,这个文件是由ireport文件编译.jrxml文件之后生成的。这个需要注意的是JasperReport和ireport的版本一定要对应,否则很可能出问题。下面的文件就是.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="report name" pageWidth="595" pageHeight="842" whenNoDataType="AllSectionsNoDetail" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" isIgnorePagination="true">
	<style name="title" isDefault="false" vAlign="Middle" pattern="" fontName="宋体" fontSize="20" isItalic="false" isUnderline="false" pdfFontName="C:\WINDOWS\Fonts\SIMKAI.TTF" pdfEncoding="Identity-H" isPdfEmbedded="true"/>
	<style name="cellCenterNoBorder" isDefault="false" hAlign="Center" vAlign="Middle" lineSpacing="Single" fontName="宋体" fontSize="12" isBold="false" isItalic="false" isUnderline="false" isStrikeThrough="false" pdfFontName="C:\WINDOWS\Fonts\SIMKAI.TTF" pdfEncoding="Identity-H" isPdfEmbedded="true"/>
	<style name="cellleftNoBorder" isDefault="false" hAlign="Left" vAlign="Middle" lineSpacing="Single" fontName="宋体" fontSize="12" isBold="false" isItalic="false" isUnderline="false" isStrikeThrough="false" pdfFontName="C:\WINDOWS\Fonts\SIMKAI.TTF" pdfEncoding="Identity-H" isPdfEmbedded="true"/>
	<style name="cellRightNoBorder" isDefault="false" hAlign="Right" vAlign="Middle" lineSpacing="Single" fontName="宋体" fontSize="12" isBold="false" isItalic="false" isUnderline="false" isStrikeThrough="false" pdfFontName="C:\WINDOWS\Fonts\SIMKAI.TTF" pdfEncoding="Identity-H" isPdfEmbedded="true"/>
	<style name="cellCenterHasBorder" isDefault="false" hAlign="Center" vAlign="Middle" lineSpacing="Single" fontName="宋体" fontSize="12" isBold="false" isItalic="false" isUnderline="false" isStrikeThrough="false" pdfFontName="C:\WINDOWS\Fonts\SIMKAI.TTF" pdfEncoding="Identity-H" isPdfEmbedded="true">
		<pen lineWidth="0.5" lineColor="#000000"/>
	</style>
	<style name="cellleftHasBorder" isDefault="false" vAlign="Middle" lineSpacing="Single" fontName="宋体" fontSize="12" isBold="false" isItalic="false" isUnderline="false" isStrikeThrough="false" pdfFontName="C:\WINDOWS\Fonts\SIMKAI.TTF" pdfEncoding="Identity-H" isPdfEmbedded="true"/>
	<style name="cellRightHasBorder" isDefault="false" hAlign="Right" vAlign="Middle" lineSpacing="Single" fontName="宋体" fontSize="12" isBold="false" isItalic="false" isUnderline="false" isStrikeThrough="false" pdfFontName="C:\WINDOWS\Fonts\SIMKAI.TTF" pdfEncoding="Identity-H" isPdfEmbedded="true"/>
	<field name="PID" class="java.lang.String"/>
	<field name="PROJECTCODE" class="java.lang.String"/>
	<field name="SELLER" class="java.lang.String"/>
	<field name="WITHDRAWDAY" class="java.lang.String"/>
	<field name="FINANCINGPARTY" class="java.lang.String"/>
	<field name="PERIOD" class="java.lang.String"/>
	<field name="PAYMETHOD" class="java.lang.String"/>
	<field name="PUBLISHDAY" class="java.lang.String"/>
	<field name="RATE" class="java.lang.String"/>
	<field name="INTEREST" class="java.lang.String"/>
	<field name="ENDDAY" class="java.lang.String"/>
	<field name="FINANCINGAMOUNT" class="java.math.BigDecimal"/>
	<field name="PROJECTNAME" class="java.lang.String"/>
	<background>
		<band splitType="Stretch"/>
	</background>
	<title>
		<band height="1" splitType="Stretch"/>
	</title>
	<pageHeader>
		<band splitType="Stretch"/>
	</pageHeader>
	<columnHeader>
		<band height="33" splitType="Stretch">
			<staticText>
				<reportElement style="cellCenterHasBorder" x="0" y="0" width="28" height="33"/>
				<box>
					<pen lineWidth="0.25"/>
					<topPen lineWidth="0.25"/>
					<leftPen lineWidth="0.25"/>
					<bottomPen lineWidth="0.25"/>
					<rightPen lineWidth="0.25"/>
				</box>
				<textElement>
					<font isBold="true" pdfFontName="STSong-Light" pdfEncoding="UniGB-UCS2-H"/>
				</textElement>
				<text><![CDATA[序号]]></text>
			</staticText>
			<staticText>
				<reportElement style="cellCenterHasBorder" x="470" y="0" width="49" height="33"/>
				<box>
					<pen lineWidth="0.25"/>
					<topPen lineWidth="0.25"/>
					<leftPen lineWidth="0.25"/>
					<bottomPen lineWidth="0.25"/>
					<rightPen lineWidth="0.25"/>
				</box>
				<textElement>
					<font isBold="true" pdfFontName="STSong-Light" pdfEncoding="UniGB-UCS2-H"/>
				</textElement>
				<text><![CDATA[融资金额]]></text>
			</staticText>
			<staticText>
				<reportElement style="cellCenterHasBorder" x="519" y="0" width="36" height="33"/>
				<box>
					<pen lineWidth="0.25"/>
					<topPen lineWidth="0.25"/>
					<leftPen lineWidth="0.25"/>
					<bottomPen lineWidth="0.25"/>
					<rightPen lineWidth="0.25"/>
				</box>
				<textElement>
					<font isBold="true" pdfFontName="STSong-Light" pdfEncoding="UniGB-UCS2-H"/>
				</textElement>
				<text><![CDATA[利息]]></text>
			</staticText>
			<staticText>
				<reportElement style="cellCenterHasBorder" x="426" y="0" width="44" height="33"/>
				<box>
					<pen lineWidth="0.25"/>
					<topPen lineWidth="0.25"/>
					<leftPen lineWidth="0.25"/>
					<bottomPen lineWidth="0.25"/>
					<rightPen lineWidth="0.25"/>
				</box>
				<textElement>
					<font isBold="true" pdfFontName="STSong-Light" pdfEncoding="UniGB-UCS2-H"/>
				</textElement>
				<text><![CDATA[利率]]></text>
			</staticText>
			<staticText>
				<reportElement style="cellCenterHasBorder" x="373" y="0" width="53" height="33"/>
				<box>
					<pen lineWidth="0.25"/>
					<topPen lineWidth="0.25"/>
					<leftPen lineWidth="0.25"/>
					<bottomPen lineWidth="0.25"/>
					<rightPen lineWidth="0.25"/>
				</box>
				<textElement>
					<font isBold="true" pdfFontName="STSong-Light" pdfEncoding="UniGB-UCS2-H"/>
				</textElement>
				<text><![CDATA[到期日]]></text>
			</staticText>
			<staticText>
				<reportElement style="cellCenterHasBorder" x="109" y="0" width="34" height="33"/>
				<box>
					<pen lineWidth="0.25"/>
					<topPen lineWidth="0.25"/>
					<leftPen lineWidth="0.25"/>
					<bottomPen lineWidth="0.25"/>
					<rightPen lineWidth="0.25"/>
				</box>
				<textElement>
					<font isBold="true" pdfFontName="STSong-Light" pdfEncoding="UniGB-UCS2-H"/>
				</textElement>
				<text><![CDATA[卖方]]></text>
			</staticText>
			<staticText>
				<reportElement style="cellCenterHasBorder" x="143" y="0" width="42" height="33"/>
				<box>
					<pen lineWidth="0.25"/>
					<topPen lineWidth="0.25"/>
					<leftPen lineWidth="0.25"/>
					<bottomPen lineWidth="0.25"/>
					<rightPen lineWidth="0.25"/>
				</box>
				<textElement>
					<font isBold="true" pdfFontName="STSong-Light" pdfEncoding="UniGB-UCS2-H"/>
				</textElement>
				<text><![CDATA[对方提现日]]></text>
			</staticText>
			<staticText>
				<reportElement style="cellCenterHasBorder" x="185" y="0" width="49" height="33"/>
				<box>
					<pen lineWidth="0.25"/>
					<topPen lineWidth="0.25"/>
					<leftPen lineWidth="0.25"/>
					<bottomPen lineWidth="0.25"/>
					<rightPen lineWidth="0.25"/>
				</box>
				<textElement>
					<font isBold="true" pdfFontName="STSong-Light" pdfEncoding="UniGB-UCS2-H"/>
				</textElement>
				<text><![CDATA[融资方]]></text>
			</staticText>
			<staticText>
				<reportElement style="cellCenterHasBorder" x="234" y="0" width="35" height="33"/>
				<box>
					<pen lineWidth="0.25"/>
					<topPen lineWidth="0.25"/>
					<leftPen lineWidth="0.25"/>
					<bottomPen lineWidth="0.25"/>
					<rightPen lineWidth="0.25"/>
				</box>
				<textElement>
					<font isBold="true" pdfFontName="STSong-Light" pdfEncoding="UniGB-UCS2-H"/>
				</textElement>
				<text><![CDATA[期限]]></text>
			</staticText>
			<staticText>
				<reportElement style="cellCenterHasBorder" x="269" y="0" width="51" height="33"/>
				<box>
					<pen lineWidth="0.25"/>
					<topPen lineWidth="0.25"/>
					<leftPen lineWidth="0.25"/>
					<bottomPen lineWidth="0.25"/>
					<rightPen lineWidth="0.25"/>
				</box>
				<textElement>
					<font isBold="true" pdfFontName="STSong-Light" pdfEncoding="UniGB-UCS2-H"/>
				</textElement>
				<text><![CDATA[付款方式]]></text>
			</staticText>
			<staticText>
				<reportElement style="cellCenterHasBorder" x="320" y="0" width="53" height="33"/>
				<box>
					<pen lineWidth="0.25"/>
					<topPen lineWidth="0.25"/>
					<leftPen lineWidth="0.25"/>
					<bottomPen lineWidth="0.25"/>
					<rightPen lineWidth="0.25"/>
				</box>
				<textElement>
					<font isBold="true" pdfFontName="STSong-Light" pdfEncoding="UniGB-UCS2-H"/>
				</textElement>
				<text><![CDATA[发标日期]]></text>
			</staticText>
			<staticText>
				<reportElement style="cellCenterHasBorder" x="28" y="0" width="40" height="33"/>
				<box>
					<pen lineWidth="0.25"/>
					<topPen lineWidth="0.25"/>
					<leftPen lineWidth="0.25"/>
					<bottomPen lineWidth="0.25"/>
					<rightPen lineWidth="0.25"/>
				</box>
				<textElement>
					<font isBold="true" pdfFontName="STSong-Light" pdfEncoding="UniGB-UCS2-H"/>
				</textElement>
				<text><![CDATA[项目编号]]></text>
			</staticText>
			<staticText>
				<reportElement x="68" y="0" width="41" height="33"/>
				<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">
					<font size="12" isBold="true"/>
				</textElement>
				<text><![CDATA[项目名称]]></text>
			</staticText>
		</band>
	</columnHeader>
	<detail>
		<band height="33" splitType="Stretch">
			<textField isStretchWithOverflow="true" isBlankWhenNull="true">
				<reportElement style="cellCenterHasBorder" stretchType="RelativeToTallestObject" x="185" y="0" width="49" height="33"/>
				<box>
					<pen lineWidth="0.25"/>
					<topPen lineWidth="0.25"/>
					<leftPen lineWidth="0.25"/>
					<bottomPen lineWidth="0.25"/>
					<rightPen lineWidth="0.25"/>
				</box>
				<textElement>
					<font pdfFontName="STSong-Light" pdfEncoding="UniGB-UCS2-H"/>
				</textElement>
				<textFieldExpression class="java.lang.String"><![CDATA[$F{FINANCINGPARTY}]]></textFieldExpression>
			</textField>
			<textField isStretchWithOverflow="true" isBlankWhenNull="true">
				<reportElement style="cellCenterHasBorder" stretchType="RelativeToTallestObject" x="234" y="0" width="35" height="33"/>
				<box>
					<pen lineWidth="0.25"/>
					<topPen lineWidth="0.25"/>
					<leftPen lineWidth="0.25"/>
					<bottomPen lineWidth="0.25"/>
					<rightPen lineWidth="0.25"/>
				</box>
				<textElement>
					<font pdfFontName="STSong-Light" pdfEncoding="UniGB-UCS2-H"/>
				</textElement>
				<textFieldExpression class="java.lang.String"><![CDATA[$F{PERIOD}]]></textFieldExpression>
			</textField>
			<textField isStretchWithOverflow="true" isBlankWhenNull="true">
				<reportElement style="cellCenterHasBorder" stretchType="RelativeToTallestObject" x="269" y="0" width="51" height="33"/>
				<box>
					<pen lineWidth="0.25"/>
					<topPen lineWidth="0.25"/>
					<leftPen lineWidth="0.25"/>
					<bottomPen lineWidth="0.25"/>
					<rightPen lineWidth="0.25"/>
				</box>
				<textElement>
					<font pdfFontName="STSong-Light" pdfEncoding="UniGB-UCS2-H"/>
				</textElement>
				<textFieldExpression class="java.lang.String"><![CDATA[$F{PAYMETHOD}]]></textFieldExpression>
			</textField>
			<textField isStretchWithOverflow="true" isBlankWhenNull="true">
				<reportElement style="cellCenterHasBorder" stretchType="RelativeToTallestObject" x="320" y="0" width="53" height="33"/>
				<box>
					<pen lineWidth="0.25"/>
					<topPen lineWidth="0.25"/>
					<leftPen lineWidth="0.25"/>
					<bottomPen lineWidth="0.25"/>
					<rightPen lineWidth="0.25"/>
				</box>
				<textElement>
					<font pdfFontName="STSong-Light" pdfEncoding="UniGB-UCS2-H"/>
				</textElement>
				<textFieldExpression class="java.lang.String"><![CDATA[$F{PUBLISHDAY}]]></textFieldExpression>
			</textField>
			<textField isStretchWithOverflow="true" isBlankWhenNull="true">
				<reportElement style="cellCenterHasBorder" stretchType="RelativeToTallestObject" x="0" y="0" width="28" height="33"/>
				<box>
					<pen lineWidth="0.25"/>
					<topPen lineWidth="0.25"/>
					<leftPen lineWidth="0.25"/>
					<bottomPen lineWidth="0.25"/>
					<rightPen lineWidth="0.25"/>
				</box>
				<textElement>
					<font pdfFontName="STSong-Light" pdfEncoding="UniGB-UCS2-H"/>
				</textElement>
				<textFieldExpression class="java.lang.String"><![CDATA[$F{PID}]]></textFieldExpression>
			</textField>
			<textField isStretchWithOverflow="true" isBlankWhenNull="true">
				<reportElement style="cellCenterHasBorder" stretchType="RelativeToTallestObject" x="109" y="0" width="34" height="33"/>
				<box>
					<pen lineWidth="0.25"/>
					<topPen lineWidth="0.25"/>
					<leftPen lineWidth="0.25"/>
					<bottomPen lineWidth="0.25"/>
					<rightPen lineWidth="0.25"/>
				</box>
				<textElement>
					<font pdfFontName="STSong-Light" pdfEncoding="UniGB-UCS2-H"/>
				</textElement>
				<textFieldExpression class="java.lang.String"><![CDATA[$F{SELLER}]]></textFieldExpression>
			</textField>
			<textField isStretchWithOverflow="true" isBlankWhenNull="true">
				<reportElement style="cellCenterHasBorder" stretchType="RelativeToTallestObject" x="519" y="0" width="36" height="33"/>
				<box>
					<pen lineWidth="0.25"/>
					<topPen lineWidth="0.25"/>
					<leftPen lineWidth="0.25"/>
					<bottomPen lineWidth="0.25"/>
					<rightPen lineWidth="0.25"/>
				</box>
				<textElement>
					<font pdfFontName="STSong-Light" pdfEncoding="UniGB-UCS2-H"/>
				</textElement>
				<textFieldExpression class="java.lang.String"><![CDATA[$F{INTEREST}]]></textFieldExpression>
			</textField>
			<textField isStretchWithOverflow="true" isBlankWhenNull="true">
				<reportElement style="cellCenterHasBorder" stretchType="RelativeToTallestObject" x="426" y="0" width="44" height="33"/>
				<box>
					<pen lineWidth="0.25"/>
					<topPen lineWidth="0.25"/>
					<leftPen lineWidth="0.25"/>
					<bottomPen lineWidth="0.25"/>
					<rightPen lineWidth="0.25"/>
				</box>
				<textElement>
					<font pdfFontName="STSong-Light" pdfEncoding="UniGB-UCS2-H"/>
				</textElement>
				<textFieldExpression class="java.lang.String"><![CDATA[$F{RATE}]]></textFieldExpression>
			</textField>
			<textField isStretchWithOverflow="true" isBlankWhenNull="true">
				<reportElement style="cellCenterHasBorder" stretchType="RelativeToTallestObject" x="28" y="0" width="40" height="33"/>
				<box>
					<pen lineWidth="0.25"/>
					<topPen lineWidth="0.25"/>
					<leftPen lineWidth="0.25"/>
					<bottomPen lineWidth="0.25"/>
					<rightPen lineWidth="0.25"/>
				</box>
				<textElement>
					<font pdfFontName="STSong-Light" pdfEncoding="UniGB-UCS2-H"/>
				</textElement>
				<textFieldExpression class="java.lang.String"><![CDATA[$F{PROJECTCODE}]]></textFieldExpression>
			</textField>
			<textField isStretchWithOverflow="true" isBlankWhenNull="true">
				<reportElement style="cellCenterHasBorder" stretchType="RelativeToTallestObject" x="373" y="0" width="53" height="33"/>
				<box>
					<pen lineWidth="0.25"/>
					<topPen lineWidth="0.25"/>
					<leftPen lineWidth="0.25"/>
					<bottomPen lineWidth="0.25"/>
					<rightPen lineWidth="0.25"/>
				</box>
				<textElement>
					<font pdfFontName="STSong-Light" pdfEncoding="UniGB-UCS2-H"/>
				</textElement>
				<textFieldExpression class="java.lang.String"><![CDATA[$F{ENDDAY}]]></textFieldExpression>
			</textField>
			<textField isStretchWithOverflow="true" isBlankWhenNull="true">
				<reportElement style="cellCenterHasBorder" stretchType="RelativeToTallestObject" x="470" y="0" width="49" height="33"/>
				<box>
					<pen lineWidth="0.25"/>
					<topPen lineWidth="0.25"/>
					<leftPen lineWidth="0.25"/>
					<bottomPen lineWidth="0.25"/>
					<rightPen lineWidth="0.25"/>
				</box>
				<textElement>
					<font pdfFontName="STSong-Light" pdfEncoding="UniGB-UCS2-H"/>
				</textElement>
				<textFieldExpression class="java.math.BigDecimal"><![CDATA[$F{FINANCINGAMOUNT}]]></textFieldExpression>
			</textField>
			<textField isStretchWithOverflow="true" isBlankWhenNull="true">
				<reportElement style="cellCenterHasBorder" stretchType="RelativeToTallestObject" x="68" y="0" width="41" height="33"/>
				<box>
					<pen lineWidth="0.25"/>
					<topPen lineWidth="0.25"/>
					<leftPen lineWidth="0.25"/>
					<bottomPen lineWidth="0.25"/>
					<rightPen lineWidth="0.25"/>
				</box>
				<textElement>
					<font pdfFontName="STSong-Light" pdfEncoding="UniGB-UCS2-H"/>
				</textElement>
				<textFieldExpression class="java.lang.String"><![CDATA[$F{PROJECTNAME}]]></textFieldExpression>
			</textField>
			<textField isStretchWithOverflow="true" isBlankWhenNull="true">
				<reportElement style="cellCenterHasBorder" stretchType="RelativeToTallestObject" x="143" y="0" width="42" height="33"/>
				<box>
					<pen lineWidth="0.25"/>
					<topPen lineWidth="0.25"/>
					<leftPen lineWidth="0.25"/>
					<bottomPen lineWidth="0.25"/>
					<rightPen lineWidth="0.25"/>
				</box>
				<textElement>
					<font pdfFontName="STSong-Light" pdfEncoding="UniGB-UCS2-H"/>
				</textElement>
				<textFieldExpression class="java.lang.String"><![CDATA[$F{WITHDRAWDAY}]]></textFieldExpression>
			</textField>
		</band>
	</detail>
	<columnFooter>
		<band splitType="Stretch"/>
	</columnFooter>
	<pageFooter>
		<band height="58" splitType="Stretch"/>
	</pageFooter>
	<summary>
		<band splitType="Stretch"/>
	</summary>
</jasperReport>

后台执行代码JREXLServlet:

public class JREXLServlet extends HttpServlet {

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		this.doPost(request, response);
	}

	/**
	 * 生成Excel表格
	 */
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		File jasperFile = null;
		try {
			Configuration config = new  PropertiesConfiguration("config.properties");
			jasperFile = new File(config.getString("project.info.report.jasper"));
		} catch (ConfigurationException e2) {
			e2.printStackTrace();
		}
		Map<String, String> parameters = new HashMap<String, String>();
		JasperPrint jasperPrint = null;
		try {
			JasperReport jasperReport = (JasperReport) JRLoader
					.loadObject(jasperFile);
			jasperPrint = JasperFillManager.fillReport(jasperReport, parameters,
					new ReportDataSource());
		} catch (JRException e) {
			e.printStackTrace();
		}
		if(null != jasperPrint){
			FileBufferedOutputStream fbos = new FileBufferedOutputStream();
			JRXlsAbstractExporter exporter = new JRXlsExporter();
			exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, fbos);
			exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
			exporter.setParameter(JRXlsAbstractExporterParameter.IS_ONE_PAGE_PER_SHEET, Boolean.FALSE);
			exporter.setParameter(JRXlsAbstractExporterParameter.IS_WHITE_PAGE_BACKGROUND, Boolean.FALSE);
			/**不分页**/
			exporter.setParameter(JRXlsExporterParameter.IGNORE_PAGE_MARGINS,Boolean.TRUE);
			/**解决勾选stretch with overflow的折行问题**/
			exporter.setParameter(JRXlsExporterParameter.IS_COLLAPSE_ROW_SPAN,Boolean.TRUE);
			try {

				exporter.exportReport();
				fbos.close();
				if (fbos.size() > 0) {
					response.setContentType("application/xls");
					response.setHeader("Content-Disposition", "inline; filename=\"ProjectInfo.xls\"");
					response.setContentLength(fbos.size());
					ServletOutputStream ouputStream = response.getOutputStream();
					try {
						fbos.writeData(ouputStream);
						fbos.dispose();
						ouputStream.flush();
					} finally {
						if (null != ouputStream) {
							ouputStream.close();
						}
					}
				}
			} catch (JRException e1) {
				e1.printStackTrace();
			}finally{
				if(null !=fbos){
					fbos.close();
					fbos.dispose();
				}
			}
		}

	}
}

ReportService:

public class ReportService {
	public List<ProjectInfoBean> getAllPerson() {
		List<ProjectInfoBean> projectList = new ArrayList<ProjectInfoBean>();

		try{
			SqlMapClient sqlMap=DataAccessor.getSession();
			projectList = new ProjectDAO(sqlMap).queryProjectInfo();
			for(ProjectInfoBean pb : projectList){
				/**显示为具体的付款形式**/
				if("1".equals(pb.getPAYMETHOD())){
					pb.setPAYMETHOD("一次性还本付息");
				}else if("2".equals(pb.getPAYMETHOD())){
					pb.setPAYMETHOD("满标付息到期还本");
				}else if("3".equals(pb.getPAYMETHOD())){
					pb.setPAYMETHOD("按月付息到期还本");
				}else{
					pb.setPAYMETHOD("未标明付款方式");
				}
				/**期限后面加上“天”**/
				if(null != pb.getPERIOD() && !"".equals(pb.getPERIOD())){
					pb.setPERIOD(pb.getPERIOD() + "天");
				}
				/**利率后面加上“%”**/
				if(null != pb.getRATE() && !"".equals(pb.getRATE())){
					pb.setRATE(pb.getRATE() + "%");
				}
				/**去掉到期日后面的“.0”**/
				if(null != pb.getENDDAY() && !"".equals(pb.getENDDAY())){
					pb.setENDDAY(pb.getENDDAY().substring(0, pb.getENDDAY().length()-2));
				}
				/**去掉对方提现日后面的“.0”**/
				if(null != pb.getWITHDRAWDAY() && !"".equals(pb.getWITHDRAWDAY())){
					pb.setWITHDRAWDAY(pb.getWITHDRAWDAY().substring(0, pb.getWITHDRAWDAY().length()-2));
				}
				/**去掉发标日期后面的“.0”**/
				if(null != pb.getPUBLISHDAY() && !"".equals(pb.getPUBLISHDAY())){
					pb.setPUBLISHDAY(pb.getPUBLISHDAY().substring(0, pb.getPUBLISHDAY().length()-2));
				}
			}
		}catch(Exception e){
			e.printStackTrace();
		}

		return projectList;
    }
}

ReportDataSource:

public class ReportService {
	public List<ProjectInfoBean> getAllPerson() {
		List<ProjectInfoBean> projectList = new ArrayList<ProjectInfoBean>();

		try{
			SqlMapClient sqlMap=DataAccessor.getSession();
			projectList = new ProjectDAO(sqlMap).queryProjectInfo();
			for(ProjectInfoBean pb : projectList){
				/**显示为具体的付款形式**/
				if("1".equals(pb.getPAYMETHOD())){
					pb.setPAYMETHOD("一次性还本付息");
				}else if("2".equals(pb.getPAYMETHOD())){
					pb.setPAYMETHOD("满标付息到期还本");
				}else if("3".equals(pb.getPAYMETHOD())){
					pb.setPAYMETHOD("按月付息到期还本");
				}else{
					pb.setPAYMETHOD("未标明付款方式");
				}
				/**期限后面加上“天”**/
				if(null != pb.getPERIOD() && !"".equals(pb.getPERIOD())){
					pb.setPERIOD(pb.getPERIOD() + "天");
				}
				/**利率后面加上“%”**/
				if(null != pb.getRATE() && !"".equals(pb.getRATE())){
					pb.setRATE(pb.getRATE() + "%");
				}
				/**去掉到期日后面的“.0”**/
				if(null != pb.getENDDAY() && !"".equals(pb.getENDDAY())){
					pb.setENDDAY(pb.getENDDAY().substring(0, pb.getENDDAY().length()-2));
				}
				/**去掉对方提现日后面的“.0”**/
				if(null != pb.getWITHDRAWDAY() && !"".equals(pb.getWITHDRAWDAY())){
					pb.setWITHDRAWDAY(pb.getWITHDRAWDAY().substring(0, pb.getWITHDRAWDAY().length()-2));
				}
				/**去掉发标日期后面的“.0”**/
				if(null != pb.getPUBLISHDAY() && !"".equals(pb.getPUBLISHDAY())){
					pb.setPUBLISHDAY(pb.getPUBLISHDAY().substring(0, pb.getPUBLISHDAY().length()-2));
				}
			}
		}catch(Exception e){
			e.printStackTrace();
		}

		return projectList;
    }
}
<span style="font-family:Microsoft YaHei;font-size:14px;">
</span>

至于ireport设计报表格式的问题,大家自己去探索吧。

时间: 2024-08-02 03:16:41

jasperReport+ireport实现报表导出和数据分析的相关文章

利用JasperReport+iReport进行Web报表开发

用JasperReport+iReport进行Web报表开发 序言 在非常多实际的项目里,报表都是当中十分重要的组成部分,比如把查询结果以报表的形式呈现出来.这里所提到的报表可不是简单的二维表,而是拥有复杂表头的.多维的.能够在执行期从数据库中自己主动读取数据.可自己主动分页.拥有丰富的页面元素(图片,超连接等).支持分组和交叉表.支持打印.最好还能导出到Excel或Word…...(汗L).可是显而易见,报表功能越强大,提供的服务越丰富,其复杂度也就越提高,所以仅靠石器时代的手工方式生成报表是

使用JasperReport+iReport进行Web报表开发

前言 在实际工程中非常,报告是其中很重要的一部分,结果以报表的形式呈现出来.这里所提到的报表可不是简单的二维表,而是拥有复杂表头的.多维的.能够在执行期从数据库中自己主动读取数据.可自己主动分页.拥有丰富的页面元素(图片.超连接等).支持分组和交叉表.支持打印.最好还能导出到Excel或Word…...(汗L). 可是显而易见,报表功能越强大,提供的服务越丰富,其复杂度也就越提高,所以仅靠石器时代的手工方式生成报表是不能满足须要的. 所幸,眼下我们所熟知的几款报表工具功能上足够强大,并且都附有非

jasperReport+iReport的国际化(I18N)

JasperReport中,也可以根据不通的Locale来将个别信息进行国际化处理.根据我的整理,应该有以下的三种方式: (1)采用PrintWhenExpression的方式:PrintWhenExpression属性,是指在打印的时候,会根据设定的Expression(只返回布尔值)进行判定,如果为true,那么就打印信息:如果为false,那么该信息就直接不打印.采用该种方式来实现(一般是用StaticText来),需要几种国际化语言,对应的元素就要出现几次,每个元素的PrintWhenE

利用jasperReport制作web报表

作者:54dabang E-mail:[email protected] 一 前言 一直发现在网上寻找资源比较繁琐,前段时间在制作jasperReport报表时候出现了很多问题.特别是在一些细节方面,特别耗费时间.特此写下此文,希望对和我一样在初期阶段学习的同学能少走一些弯路. 二 内容简介 1)给出自己制作的jasperReport的视图效果,方便对报表工具初期学习的选择. 2)自己制作报表的测试源码和所有相关学习资料,对应所有jar包,jasperReport版本. 3)快速开发报表的一些建

第一部分:使用iReport制作报表的详细过程(Windows环境下)

提示:在有些板块,文中的图片看不到,建议到我的blog浏览文章:http://blog.csdn.net/jemlee2002/文章将会涉及3个方面的内容: 第二部分:使用Jasperreport作为报表控件开发胖客户端报表应用 第三部分:使用Jasperreport作为报表控件开发Web报表应用 1.前言 在网络上可以搜索到很多使用iReport和Jasperreport配合实现各种报表任务的文章,但是我觉得很少有一篇(几乎没有)做一个比较详细的介绍如何使用iReport制作报表的全过程,我所

kettle工具实现报表导出的初步搭建

1.下载kettle 国外网站:http://kettle.pentaho.org/需要FQ,下载慢 2.下载完成启动(windows)-->spoon.bat 3.进入界面,两个主要的tab页 4.第二个tab页里用到的 5. 第一步设定REST接口需要的参数(比如URL) 第二步调用REST接口 第三步使用JSON控件接收REST返回数据 第四步将返回数据输出到Excel中 6.url返回的json数据 7.运行结果: 8.如果自己链接数据库的话,会缺少数据库驱动,需要在lib包下面加上,如

【HOW】如何限制Reporting Services报表导出功能中格式选项

Reporting Services报表导出功能中缺省会提供多种导出格式选项,但很多情况下不需要全部的格式选项,因此需要对这些选项进行限制.下面我们以SQL Server 2008 R2为例来说明对这些选项进行限制的方法. 1. 打开报表服务配置文件:"C:\Program Files\Microsoft SQL Server\MSRS10_50.QUIST\Reporting Services\Report Server\ rsreportserver.config". 2. 在上述

Silverlight程序之:简单的Excel报表导出方法

Silverlight程序之:简单的Excel报表导出方法 概述 介绍一种简单的Excel报表导出方法. 页面效果 导出效果: 首先我们创建一个Excel表格,将我们的基本信息格式都设置好,如下图所示: 将创建好的Excel表格另存为网页. 打开VS将创建好的报表模版网页文件拖到Web项目新建的Report文件夹 修改其后缀名为aspx 打开文件 添加头部代码 <%@ Page Language="C#" ContentType="application/vnd.ms-

SAP关于标准ALV报表导出Excel的问题与解决:长数字

SAP关于标准ALV报表导出Excel的问题与解决:长数字 描述:在使用标准ALV功能时,使用本地文件可以把内容导到EXCEL中 问题:如果在报表中有类似银行账户.身份证号等较长数字的字段,直接导出EXCEL,在EXCEL中这些字段将会使用科学计数法的格式显示导致这列数据不正确. 解决方法一:导出时选择未转换的格式,然后再整理(分列) 解决方法二:使用ALV工具栏中按钮Excel适当位置 解决方法三:导出—电子表格—所有可用格式(选择“在现有XXL格式中”) ALV 导出电子表格的文件格式固定了