日韩久久久精品,亚洲精品久久久久久久久久久,亚洲欧美一区二区三区国产精品 ,一区二区福利

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

系統(tǒng) 2059 0

先看看設(shè)計(jì)的報(bào)表樣式:


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

?

生成的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[標(biāo)題]]></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[相當(dāng)于表尾]]></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[用于存放一些統(tǒng)計(jì)信息的]]></text>
			</staticText>
		</band>
	</summary>
</jasperReport>

  

?

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

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>();//傳入?yún)?shù)
		parameters.put("reportTitle", "我的第一個(gè)程序");
//		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;
	}
	
}

  
?

導(dǎo)出的HTML預(yù)覽界面:


?

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


更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號(hào)聯(lián)系: 360901061

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

【本文對(duì)您有幫助就好】

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

發(fā)表我的評(píng)論
最新評(píng)論 總共0條評(píng)論
主站蜘蛛池模板: 云霄县| 文昌市| 尉犁县| 项城市| 家居| 涿鹿县| 桐乡市| 湛江市| 仙桃市| 高州市| 清涧县| 郓城县| 曲沃县| 中卫市| 濮阳市| 大同县| 秭归县| 新干县| 冕宁县| 伊春市| 松滋市| 读书| 灵石县| 卢氏县| 张家界市| 永和县| 连云港市| 桃江县| 南丹县| 罗江县| 聂荣县| 宁陕县| 西安市| 日喀则市| 大荔县| 岑溪市| 仁化县| 友谊县| 正定县| 攀枝花市| 青岛市|