Jasper Report
Jasper Report is a open source technology.It is very helpful to create the report in the various format like xls , pdf and html. Well here i am sharing a small example with you , may be that will help you out to start with jasper Reports jasperReport.
Report Design
In JasperReports, you design reports using XML report templates. For example, the following XML file is a template for a report with a title, two columns of data, and page numbers:
Sample Xml File
Report CreationJasper Report is a open source technology.It is very helpful to create the report in the various format like xls , pdf and html. Well here i am sharing a small example with you , may be that will help you out to start with jasper Reports jasperReport.
Report Design
In JasperReports, you design reports using XML report templates. For example, the following XML file is a template for a report with a title, two columns of data, and page numbers:
Sample Xml File
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE jasperReport PUBLIC "-//JasperReports//DTD Report Design//EN" "http://jasperreports.sourceforge.net/dtds/jasperreport.dtd"> <jasperReport name="BasicReport" > <parameter name="Title" class="java.lang.String"/> <queryString><![CDATA[select name, cost from product]]></queryString> <field name="NAME" class="java.lang.String"/> <field name="COST" class="java.lang.Double"/> <title> <band height="50"> <textField> <reportElement x="0" y="0" width="200" height="50" /> <textFieldExpression class="java.lang.String">$P{Title}</textFieldExpression> </textField> </band> </title> <pageHeader> <band> </band> </pageHeader> <columnHeader> <band height="20"> <staticText> <reportElement x="180" y="0" width="180" height="20"/> <textElement> <font isUnderline="true"/> </textElement> <text><![CDATA[NAME]]></text> </staticText> <staticText> <reportElement x="360" y="0" width="180" height="20"/> <textElement> <font isUnderline="true"/> </textElement> <text><![CDATA[COST]]></text> </staticText> </band> </columnHeader> <detail> <band height="20"> <textField> <reportElement x="180" y="0" width="180" height="20"/> <textFieldExpression class="java.lang.String"><![CDATA[$F{NAME}]]></textFieldExpression> </textField> <textField pattern="0.00"> <reportElement x="360" y="0" width="180" height="20"/> <textFieldExpression class="java.lang.Double"><![CDATA[$F{COST}]]></textFieldExpression> </textField> </band> </detail> <columnFooter> <band> </band> </columnFooter> <pageFooter> <band height="15"> <staticText> <reportElement x="0" y="0" width="40" height="15"/> <textElement/> <text><![CDATA[Page:]]></text> </staticText> <textField> <reportElement x="40" y="0" width="100" height="15"/> <textElement/> <textFieldExpression class="java.lang.Integer"><![CDATA[$V{PAGE_NUMBER}]]></textFieldExpression> </textField> </band> </pageFooter> <summary> <band> </band> </summary> </jasperReport>
whenever we are dealing with jasper report object.we must have to understand the these three phases of jasper Report creation.
1. Jasper Design : - Basically a xml file , we can create that by program here i am using already created xml file.
2. Jasper Report : After compliation of jasper Design object we get JasperReport Object.
3. Jasper Print : Jasper print in which we populate the data in jasper Report.
Code Snippet
package com.simple.star;
import java.io.File;
import java.util.HashMap;
import net.sf.jasperreports.engine.JREmptyDataSource;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JasperCompileManager;
import net.sf.jasperreports.engine.JasperExportManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.JasperReport;
import net.sf.jasperreports.engine.design.JasperDesign;
import net.sf.jasperreports.engine.xml.JRXmlLoader;
import net.sf.jasperreports.view.JasperViewer;
public class CreateJasperReport {
/**
* @param args
* @throws JRException
*/
public static void main(String[] args) throws JRException
{
JasperDesign jasperdesign = JRXmlLoader.load("C:"+File.separator+"Users\\Sunil Dangayach\\workspace\\AnonomysPrograms\\src\\com\\simple\\star\\jasper.xml");
System.out.println(jasperdesign);
JasperReport jasperReport = JasperCompileManager.compileReport(jasperdesign);
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport,new HashMap
JasperExportManager.exportReportToPdf(jasperPrint);
JasperViewer.viewReport(jasperPrint);
}
}
Jars Required
Commons-beanutils-core-1.8.0.jar
Comons-collections-3.1.jar
commons-digester-2.0.jar
commons-logging-1.1.1.jar
jassperreport-4.1.2.jar
poi.jar (for xls)
Help
for more details and more clarification go throgh these links,will help you out to understand jasper reports very clearly
http://jasperforge.org/uploads/publish/jasperreportswebsite/trunk/tutorial.html
http://struts.apache.org/2.0.11.2/docs/jasperreports-tutorial.html
http://www.javaworld.com/javaworld/jw-09-2002/jw-0920-opensourceprofile.html#resources
No comments:
Post a Comment