<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- saved from url=(0065)http://www.blogjava.net/zhouzhou163/archive/2006/11/12/80760.html -->
<HTML><HEAD id=Head><TITLE>jasperreport生成html,Excel,PDF报表,数据源使用List - allen - BlogJava</TITLE>
<META http-equiv=Content-Type content="text/html; charset=utf-8">
<META id=metaKeywords content=jasperreport生成html,Excel,PDF报表,数据源使用List
name=keywords><LINK id=MainCss
href="jasperreport生成html,Excel,PDF报表,数据源使用List - allen - BlogJava.files/style.css"
type=text/css rel=stylesheet><LINK id=RSSLink title=RSS
href="http://www.blogjava.net/zhouzhou163/rss.aspx" type=application/rss+xml
rel=alternate>
<META content="MSHTML 6.00.2900.3354" name=GENERATOR></HEAD>
<BODY>
<FORM id=Form1 name=Form1 onsubmit="javascript:return WebForm_OnSubmit();"
action=80760.html method=post>
<DIV><INPUT id=__EVENTTARGET type=hidden name=__EVENTTARGET> <INPUT
id=__EVENTARGUMENT type=hidden name=__EVENTARGUMENT> <INPUT
id=" __VIEWSTATE" type=hidden name=__VIEWSTATE> </DIV>
<SCRIPT type=text/javascript>
//<![CDATA[
var theForm = document.forms['Form1'];
if (!theForm) {
theForm = document.Form1;
}
function __doPostBack(eventTarget, eventArgument) {
if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
theForm.__EVENTTARGET.value = eventTarget;
theForm.__EVENTARGUMENT.value = eventArgument;
theForm.submit();
}
}
//]]>
</SCRIPT>
<SCRIPT
src="jasperreport生成html,Excel,PDF报表,数据源使用List - allen - BlogJava.files/WebResource.axd"
type=text/javascript></SCRIPT>
<SCRIPT language=JavaScript>
function ctlent(evt,id)
{
if(evt.ctrlKey && evt.keyCode == 13)
{
try
{
TempSave(id);
}
catch(ex)
{
}
finally
{
__doPostBack('AjaxHolder$PostComment$btnSubmit','')
}
}
}</SCRIPT>
<SCRIPT language=JavaScript>function SetReplyAuhor(author){document.getElementById('AjaxHolder_PostComment_tbComment').value+="@"+author+"\n";document.getElementById('AjaxHolder_PostComment_tbComment').focus();return false}</SCRIPT>
<SCRIPT
src="jasperreport生成html,Excel,PDF报表,数据源使用List - allen - BlogJava.files/ScriptResource.axd"
type=text/javascript></SCRIPT>
<SCRIPT
src="C:\Documents and Settings\Administrator\桌面\jasperreport生成html,Excel,PDF报表,数据源使用List - allen - BlogJava.files\ScriptResource(1).axd"
type=text/javascript></SCRIPT>
<SCRIPT
src="C:\Documents and Settings\Administrator\桌面\jasperreport生成html,Excel,PDF报表,数据源使用List - allen - BlogJava.files\ScriptResource(2).axd"
type=text/javascript></SCRIPT>
<SCRIPT type=text/javascript>
//<![CDATA[
function WebForm_OnSubmit() {
if (typeof(ValidatorOnSubmit) == "function" && ValidatorOnSubmit() == false) return false;
return true;
}
//]]>
</SCRIPT>
<!--done-->
<TABLE cellSpacing=0 cellPadding=0 width="100%" align=center border=0>
<TBODY>
<TR>
<TD width=299
background="jasperreport生成html,Excel,PDF报表,数据源使用List - allen - BlogJava.files/banner1.jpg"></TD>
<TD
background="jasperreport生成html,Excel,PDF报表,数据源使用List - allen - BlogJava.files/banner.jpg"><!--done-->
<DIV class=header>
<DIV class=headerText><A class=headermaintitle id=Header1_HeaderTitle
href="http://www.blogjava.net/zhouzhou163/">allen</A><BR>专注于java
ee技术,包括struts,jsf,webwork,spring,hibernate,ibatis </DIV></DIV></TD>
<TD width=296
background="jasperreport生成html,Excel,PDF报表,数据源使用List - allen - BlogJava.files/banner2.jpg"></TD></TR></TBODY></TABLE>
<DIV id=mylinks><!--done--><A class=menu id=MyLinks1_HomeLink
href="http://www.blogjava.net/">BlogJava</A> <A class=menu
id=MyLinks1_MyHomeLink
href="http://www.blogjava.net/zhouzhou163/">首页</A> <A
class=menu id=MyLinks1_NewArticleLink
href="http://www.blogjava.net/EnterMyBlog.aspx?NewArticle=1">新文章</A>
<A class=menu id=MyLinks1_NewPostLink
href="http://www.blogjava.net/zhouzhou163/admin/EditPosts.aspx?opt=1">新随笔</A>
<A class=menu id=MyLinks1_Syndication
href="http://www.blogjava.net/zhouzhou163/rss">聚合</A><A id=MyLinks1_XMLLink
href="http://www.blogjava.net/zhouzhou163/rss"><IMG
style="BORDER-TOP-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-RIGHT-WIDTH: 0px"
src="jasperreport生成html,Excel,PDF报表,数据源使用List - allen - BlogJava.files/xml.gif"></A>
<A class=menu id=MyLinks1_Admin
href="http://www.blogjava.net/zhouzhou163/admin/EditPosts.aspx">管理</A> <!-- <a id="MyLinks1_ContactLink" accesskey="9" class="menu" href="http://www.blogjava.net/zhouzhou163/contact.aspx?id=1">联系</a> --></DIV>
<DIV id=mytopmenu>
<DIV id=mystats><!--done-->
<DIV class=blogStats>posts - 6, comments - 5, trackbacks - 0
</DIV></DIV></DIV>
<DIV id=centercontent><!--done-->
<DIV class=post>
<DIV class=postTitle><A class=postTitle2 id=viewpost1_TitleUrl
href="http://www.blogjava.net/zhouzhou163/archive/2006/11/12/80760.html">jasperreport生成html,Excel,PDF报表,数据源使用List</A>
</DIV>
<P>jasperreport中可以使用List作为数据源,使用格式如下.<BR>List
list=this.customerDao.getAllCustomer();
//得到所有客户<BR>JRBeanCollectionDataSource ds = new
JRBeanCollectionDataSource(list);<BR> JasperPrint jasperPrint =
JasperFillManager.fillReport(<BR> reportFilePath,
parameters, ds);<BR>得填充数据后,即可输出显示到PDF,Excel,Html<BR>到PDF:<BR>public byte[]
generatePDF(String begCustNo, String endCustNo,<BR> String
reportTitle, String reportFilePath) throws DemoException {<BR> //
TODO Auto-generated method
stub<BR> //begCustNo,endCustNo分别为查询传入的开始编号,结束编号.<BR> jdbcCustomerDao
= new JdbcCustomerDao();<BR> Map parameters = new
HashMap();<BR> parameters.put("ReportTitle",
reportTitle);//报表标题<BR> List list =
jdbcCustomerDao.getAllCustomer(begCustNo, endCustNo);<BR> try
{<BR> JRBeanCollectionDataSource ds = new
JRBeanCollectionDataSource(list);<BR> JasperPrint jasperPrint =
JasperFillManager.fillReport(<BR> reportFilePath,
parameters, ds); return
JasperExportManager.exportReportToPdf(jasperPrint);<BR> } catch
(JRException e) {<BR> throw new DemoException("Report Export
Failed.");<BR> }<BR> }<BR>到Html:<BR>public byte[]
generateHtml(String begCustNo, String endCustNo,<BR> String
reportTitle, String reportFilePath) throws DemoException
{<BR> jdbcCustomerDao = new JdbcCustomerDao();<BR> Map
parameters = new HashMap();<BR> parameters.put("ReportTitle",
reportTitle);<BR> List list =
jdbcCustomerDao.getAllCustomer(begCustNo,
endCustNo);<BR> System.out.println("list size is :" +
list.size());<BR> JRHtmlExporter exporter = new
JRHtmlExporter();<BR> ByteArrayOutputStream oStream = new
ByteArrayOutputStream();<BR> try
{<BR> JRBeanCollectionDataSource ds = new
JRBeanCollectionDataSource(list);<BR> JasperPrint jasperPrint =
JasperFillManager.fillReport(<BR> reportFilePath,
parameters,
ds);<BR> exporter.setParameter(<BR>&n
评论3