欧美三区_成人在线免费观看视频_欧美极品少妇xxxxⅹ免费视频_a级毛片免费播放_鲁一鲁中文字幕久久_亚洲一级特黄

JasperReport(3)——Java簡單使用IReport生成的

系統 1830 0

先看看設計的報表樣式:


JasperReport(3)——Java簡單使用IReport生成的文件建立報表
?reportTitle是新添加的一個參數,而其他的id和name是通過數據源得到的Filed。IReport在設置參數的時候需要先在左邊新建一個parameter,然后再把該parameter托到右邊的設計欄中。

?

生成的XML文件為:

    <?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="report3" language="groovy" pageWidth="595" pageHeight="842" whenNoDataType="AllSectionsNoDetail" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20">
	<property name="ireport.zoom" value="1.0"/>
	<property name="ireport.x" value="0"/>
	<property name="ireport.y" value="0"/>
	<queryString>
		<![CDATA[select * from t_blog;]]>
	</queryString>
	<field name="id" class="java.lang.Integer"/>
	<field name="content" class="java.lang.String"/>
	<field name="postTime" class="java.sql.Timestamp"/>
	<field name="seenCount" class="java.lang.Integer"/>
	<field name="title" class="java.lang.String"/>
	<field name="blogStore" class="java.lang.Integer"/>
	<field name="owner" class="java.lang.Integer"/>
	<field name="sysCategory" class="java.lang.Integer"/>
	<background>
		<band splitType="Stretch"/>
	</background>
	<title>
		<band height="44" splitType="Stretch">
			<staticText>
				<reportElement x="227" y="12" width="100" height="20" forecolor="#FF0000"/>
				<textElement textAlignment="Center">
					<font size="13" isBold="true"/>
				</textElement>
				<text><![CDATA[標題]]></text>
			</staticText>
		</band>
	</title>
	<pageHeader>
		<band height="35" splitType="Stretch">
			<staticText>
				<reportElement x="227" y="15" width="100" height="20" forecolor="#FF0000"/>
				<textElement textAlignment="Center">
					<font size="13" isBold="true"/>
				</textElement>
				<text><![CDATA[頁眉]]></text>
			</staticText>
		</band>
	</pageHeader>
	<columnHeader>
		<band height="40" splitType="Stretch">
			<staticText>
				<reportElement x="70" y="2" width="100" height="20"/>
				<textElement/>
				<text><![CDATA[id]]></text>
			</staticText>
			<staticText>
				<reportElement x="214" y="2" width="100" height="20"/>
				<textElement/>
				<text><![CDATA[title]]></text>
			</staticText>
			<staticText>
				<reportElement x="373" y="2" width="100" height="20"/>
				<textElement/>
				<text><![CDATA[postTime]]></text>
			</staticText>
		</band>
	</columnHeader>
	<detail>
		<band height="81" splitType="Stretch">
			<textField>
				<reportElement x="70" y="24" width="100" height="20"/>
				<textElement/>
				<textFieldExpression><![CDATA[$F{id}]]></textFieldExpression>
			</textField>
			<textField>
				<reportElement x="214" y="25" width="100" height="20"/>
				<textElement/>
				<textFieldExpression><![CDATA[$F{title}]]></textFieldExpression>
			</textField>
			<textField>
				<reportElement x="373" y="26" width="100" height="20"/>
				<textElement/>
				<textFieldExpression><![CDATA[$F{postTime}]]></textFieldExpression>
			</textField>
		</band>
	</detail>
	<columnFooter>
		<band height="40" splitType="Stretch">
			<staticText>
				<reportElement x="227" y="10" width="100" height="20" forecolor="#FF0000"/>
				<textElement textAlignment="Center">
					<font size="13" isBold="true"/>
				</textElement>
				<text><![CDATA[相當于表尾]]></text>
			</staticText>
		</band>
	</columnFooter>
	<pageFooter>
		<band height="43" splitType="Stretch">
			<staticText>
				<reportElement x="227" y="13" width="100" height="20" forecolor="#FF0000"/>
				<textElement textAlignment="Center">
					<font size="13" isBold="true"/>
				</textElement>
				<text><![CDATA[頁腳]]></text>
			</staticText>
		</band>
	</pageFooter>
	<summary>
		<band height="41" splitType="Stretch">
			<staticText>
				<reportElement x="227" y="10" width="100" height="20" forecolor="#FF0000"/>
				<textElement textAlignment="Center">
					<font size="13" isBold="true"/>
				</textElement>
				<text><![CDATA[用于存放一些統計信息的]]></text>
			</staticText>
		</band>
	</summary>
</jasperReport>

  

?

JasperReport在生成報表的時候可以直接操作jrxml文件,然后通過Java代碼編譯為.jasper文件,也可以直接操作IReport編譯好的.jasper文件,下面就是用的直接操作.jasper文件,注釋掉的是操作jrxml文件的。JasperReport可以把生成的報表導出為多種格式,下面導出的是普通的HTML。JasperReport在往模版里面設置參數值,是提供一個Map進行參數傳入的。

java代碼:

    import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;

import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JasperExportManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.JasperReport;

public class Test2 {

	public static void main(String args[]) throws JRException, ClassNotFoundException, SQLException, FileNotFoundException {
		String fileName = "E:\\reports\\report2.jrxml";//直接操作生成的jrxml文件
		JasperReport jasperReport = null;
		JasperPrint jasperPrint = null;
//		jasperReport = JasperCompileManager.compileReport(fileName);//編譯jrxml文件
		InputStream inputStream = new FileInputStream("E:\\reports\\report2.jasper");
		Map<String, Object> parameters = new HashMap<String, Object>();//傳入參數
		parameters.put("reportTitle", "我的第一個程序");
//		jasperPrint = JasperFillManager.fillReport(jasperReport, parameters, getConnection());
		jasperPrint = JasperFillManager.fillReport(inputStream, parameters, getConnection());
		JasperExportManager.exportReportToHtmlFile(jasperPrint, "first.html");
	}
	
	public static Connection getConnection() throws ClassNotFoundException, SQLException {
		Connection conn = null;
		Class.forName("com.mysql.jdbc.Driver");
		conn = DriverManager.getConnection("jdbc:mysql://localhost/blog", "root", "root");
		return conn;
	}
	
}

  
?

導出的HTML預覽界面:


?

JasperReport(3)——Java簡單使用IReport生成的文件建立報表


更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!!!

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 亚洲不卡视频在线 | 欧美午夜视频 | 天天干天天插天天 | 91视频精选| 丝袜捆绑调教视频免费区 | 国产精品一二区 | 欧美综合激情网 | 一区二区三区在线免费看 | 亚洲欧美日韩中文综合在线不卡 | 国产日产精品一区二区三区四区 | 久久精品欧美一区二区三区不卡 | 日韩亚洲视频 | 狠狠干天天色 | 九九视频在线看精品 | 12306午夜被窝播播影院yw188 | 免费精品美女久久久久久久久久 | 天天在线欧美精品免费看 | 国产亚洲精品久久久久久国模美 | 欧美日韩a | 日韩欧美精品在线 | 国产午夜精品一区二区三区嫩草 | 九九久久精品 | 日本无卡无吗在线 | 欧美色欧美亚洲另类二区精品 | 欧美日韩综合一区 | 亚洲第一第二区 | 日韩精品在线一区二区 | 中文字幕一区二区三 | 日韩欧美一区二区三区四区 | 久久精品99久久 | 国产在视频线精品视频www666 | 成人看的一级毛片 | 亚洲日韩欧美综合 | www午夜视频 | 欧美日韩亚洲国产 | 久久综合丝袜长腿丝袜 | aⅴ在线免费观看 | 日本一区二区免费看 | 在线成人| 黄色羞羞视频在线观看 | 成人精品视频 |