转自:http://www.blogjava.net/vjame/archive/2013/10/12/404908.html
一、创建简单的jrxml文件
这里可以手动创建jrxml文件,也可以使用ireport设计器创建
2
![](http://www.blogjava.net/Images/OutliningIndicators/None.gif)
3
![](http://www.blogjava.net/Images/OutliningIndicators/None.gif)
4
![](http://www.blogjava.net/Images/OutliningIndicators/None.gif)
5
![](http://www.blogjava.net/Images/OutliningIndicators/None.gif)
6
![](http://www.blogjava.net/Images/OutliningIndicators/None.gif)
7
![](http://www.blogjava.net/Images/OutliningIndicators/None.gif)
8
![](http://www.blogjava.net/Images/OutliningIndicators/None.gif)
9
![](http://www.blogjava.net/Images/OutliningIndicators/None.gif)
10
![](http://www.blogjava.net/Images/OutliningIndicators/None.gif)
11
![](http://www.blogjava.net/Images/OutliningIndicators/None.gif)
12
![](http://www.blogjava.net/Images/OutliningIndicators/None.gif)
13
![](http://www.blogjava.net/Images/OutliningIndicators/None.gif)
14
![](http://www.blogjava.net/Images/OutliningIndicators/None.gif)
以上是一个简单的JRXML文件,实际上就是一个标准的XML文件,<jasperReport>是根元素,<staticText>表示静态的数据,<reportElement>定义了<staticText>的位置和宽度,<text>定义了实际的静态数据。
二、把JRXML文件解析成jasper文件,文件流或JasperReport对象
编译jrxml生成jasper文件
生成文件流
public static void compileReportToStream(InputStream inputStream,OutputStream outputStream)
生成报表对象
public static JasperReport compileReport("WebRoot/report/jasperreports_demo.jrxml")
三、有了JasperReport对象,文件流或jasper文件之后,就可以用JasperFillManager生成JasperPrint对象,jrprint文件,jrprint文件流
生成JasperPrint 对象
public static JasperPrint fillReport(JasperReport jasperReport,Map parameters, JRDataSource dataSource)
四、使用JasperExportManager导出或显示
JasperExportManager.exportReportToHtmlFile(jasperPrint, "c://1.html");
JasperExportManager.exportReportToPdfFile(jasperPrint, "c://1.pdf");
完整的例子
2
![](http://www.blogjava.net/Images/OutliningIndicators/None.gif)
3
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedBlockStart.gif)
4
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
5
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
6
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
7
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedBlockEnd.gif)
8
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedBlockStart.gif)
9
![](http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif)
10
![](http://www.blogjava.net/Images/OutliningIndicators/ExpandedBlockEnd.gif)