DynamicReport好不好用我不知道,但是它是开源的,文档还算全?用户的需求是想自己设计,但是ireport是给开发级别的使用的,据说用户并不想学,他们只想拖拖拽拽就出来一个报表。
功能需求总结:
1、用户自主设计报表样式
2、数据动态加载
解决方案:
将用户拖拽的结果,参照jxml的格式生成jxml文件,作为模板加载到DynamicReport里面;
数据源使用xml格式数据,可以实现动态
本文版翻译权归__馋猫和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文链接,否则保留追究法律责任的权利。
DynamicReport官方文档上面,这两个例子都有很详细的教程,链接如下:
使用模板:http://www.dynamicreports.org/examples/examples-overview#templatedesign
使用xml数据源:http://www.dynamicreports.org/examples/examples-overview#datasource
这里主要给出二者相结合使用的例子,小白级别步骤入下:
1、确定工程里面导入了DynamicReport所需要的各种jar包;
2、将 模板:testTable_subreport1.jxml和 数据源:NameList.xml添加到TestXML.Java同一包下面;
3、run即可;
package a.test.xmlfile; <?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="testTable_subreport1" language="groovy" pageWidth="555" pageHeight="802" columnWidth="555" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0" uuid="8b0d8ddc-641f-46ec-a711-a5212faff8c4"> <property name="ireport.zoom" value="1.0"/> <property name="ireport.x" value="0"/> <property name="ireport.y" value="0"/> <parameter name="SUBREPORT_DIR" class="java.lang.String" isForPrompting="false"> <defaultValueExpression><![CDATA["F:\\Users\\Desktop\\"]]></defaultValueExpression> </parameter> <queryString language="xPath"> <![CDATA[/NameList/Person]]> </queryString> <field name="Name" class="java.lang.String"> <fieldDescription><![CDATA[Name]]></fieldDescription> </field> <field name="Gender" class="java.lang.String"> <fieldDescription><![CDATA[Gender]]></fieldDescription> </field> <field name="Age" class="java.lang.String"> <fieldDescription><![CDATA[Age]]></fieldDescription> </field> <group name="GroupName" footerPosition="ForceAtBottom" keepTogether="true"> <groupExpression><![CDATA[$F{Gender}]]></groupExpression> <groupHeader> <band splitType="Immediate"/> </groupHeader> </group> <title> <band height="79" splitType="Stretch"/> </title> <pageHeader> <band height="35" splitType="Stretch"/> </pageHeader> <columnHeader> <band height="61" splitType="Stretch"> <staticText> <reportElement mode="Transparent" x="141" y="41" width="100" height="20" uuid="506dc39b-345d-40cf-af57-e6d2264b4324"/> <text><![CDATA[Name]]></text> </staticText> <staticText> <reportElement x="41" y="41" width="100" height="20" uuid="eb47f825-0875-488a-be9f-d047df0cc967"/> <text><![CDATA[Gender]]></text> </staticText> <staticText> <reportElement x="241" y="41" width="100" height="20" uuid="06a53662-6d2a-4f55-b7ca-88880fbf55a4"/> <text><![CDATA[Age]]></text> </staticText> </band> </columnHeader> <detail> <band height="21" splitType="Stretch"> <rectangle> <reportElement x="41" y="1" width="100" height="20" uuid="8016a9b4-352b-4a7b-a4db-281be1b1acff"/> </rectangle> <rectangle> <reportElement x="141" y="1" width="100" height="20" uuid="9fcc48a6-004b-4298-a1a0-8096d1f98a5d"/> </rectangle> <rectangle> <reportElement x="241" y="1" width="100" height="20" uuid="155963b8-fb26-4e85-8d94-49baae947444"/> </rectangle> <textField> <reportElement x="141" y="1" width="100" height="20" uuid="2f3e4e70-3bd1-41a1-b815-de41a96fd504"/> <textFieldExpression><![CDATA[$F{Name}]]></textFieldExpression> </textField> <textField> <reportElement x="41" y="1" width="100" height="20" uuid="51f31db4-daf2-4521-bf60-988384f93caa"/> <textFieldExpression><![CDATA[$F{Gender}]]></textFieldExpression> </textField> <textField> <reportElement x="241" y="0" width="100" height="20" uuid="80c2563c-ae7c-41ed-adcd-6ba8e09bb53d"/> <textFieldExpression><![CDATA[$F{Age}]]></textFieldExpression> </textField> </band> </detail> </jasperReport> testTable_subreport1