JasperReports-এ বিভিন্ন band ব্যবহার করে রিপোর্টের কাঠামো তৈরি করা হয়, এবং এই bands এর মাধ্যমে আপনি রিপোর্টে বিভিন্ন অংশ কাস্টমাইজ করতে পারেন, যেমন header, footer, title, summary, এবং detail। এই bands গুলি রিপোর্টের presentation এবং layout কাস্টমাইজ করার জন্য ব্যবহৃত হয়।
JasperReports Bands:
- Title Band:
- এটি রিপোর্টের প্রথম অংশ, যেখানে আপনি রিপোর্টের শিরোনাম বা অন্য প্রাথমিক তথ্য প্রদর্শন করতে পারেন।
- Page Header Band:
- এটি প্রতিটি পেজের শীর্ষে থাকে এবং সাধারণত রিপোর্টের শিরোনাম বা অন্যান্য স্থির তথ্য যেমন পেজ নম্বর, লোগো ইত্যাদি এখানে থাকে।
- Summary Band:
- এই band রিপোর্টের শেষে থাকে এবং সাধারণত রিপোর্টের উপসংহার, মোটামুটি তথ্য বা রিপোর্টের সারাংশ প্রদর্শন করে।
- Detail Band:
- এটি সবচেয়ে গুরুত্বপূর্ণ band, যেখানে আপনার মূল ডেটা প্রদর্শিত হয়। এখানে আপনি ডেটা রেকর্ড গুলি একে একে প্রদর্শন করেন, যেমন database থেকে আসা ডেটা বা JasperReports data source থেকে পাওয়া ডেটা।
- Page Footer Band:
- প্রতিটি পৃষ্ঠার শেষে থাকে এবং সাধারণত পেজ নম্বর, ডেটা বা রিপোর্টের অন্যান্য পরিসংখ্যান এখানে থাকে।
JasperReports-এর Band ব্যবহার করার একটি উদাহরণ:
Step 1: JRXML টেমপ্লেট তৈরি করা
<?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="SampleReport" language="java" pageWidth="595" pageHeight="842"
columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20">
<!-- Title Band -->
<title>
<band height="40">
<staticText>
<reportElement x="0" y="0" width="555" height="40"/>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<text><![CDATA[Employee Report]]></text>
</staticText>
</band>
</title>
<!-- Page Header Band -->
<pageHeader>
<band height="50">
<staticText>
<reportElement x="0" y="0" width="250" height="30"/>
<textElement textAlignment="Left" verticalAlignment="Middle"/>
<text><![CDATA[Company XYZ]]></text>
</staticText>
<textField>
<reportElement x="400" y="0" width="100" height="30"/>
<textFieldExpression><![CDATA["Page " + $V{PAGE_NUMBER}]]></textFieldExpression>
</textField>
</band>
</pageHeader>
<!-- Detail Band -->
<detail>
<band height="30">
<textField>
<reportElement x="0" y="0" width="200" height="30"/>
<textFieldExpression><![CDATA[$F{employee_name}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="250" y="0" width="100" height="30"/>
<textFieldExpression><![CDATA[$F{employee_age}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="400" y="0" width="100" height="30"/>
<textFieldExpression><![CDATA[$F{employee_salary}]]></textFieldExpression>
</textField>
</band>
</detail>
<!-- Summary Band -->
<summary>
<band height="50">
<staticText>
<reportElement x="0" y="0" width="555" height="50"/>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<text><![CDATA[End of Report]]></text>
</staticText>
</band>
</summary>
<!-- Page Footer Band -->
<pageFooter>
<band height="30">
<textField>
<reportElement x="400" y="0" width="100" height="30"/>
<textFieldExpression><![CDATA["Page " + $V{PAGE_NUMBER}]]></textFieldExpression>
</textField>
</band>
</pageFooter>
</jasperReport>
Bands এর ভূমিকা এবং ব্যবহার
- Title Band:
- Title section সাধারণত রিপোর্টের শিরোনাম এবং মুল উদ্দেশ্য জানিয়ে থাকে। এটি রিপোর্টের প্রথম অংশ হিসেবে প্রদর্শিত হয়।
- এই উদাহরণে, Employee Report শিরোনাম
titleband-এ রয়েছে।
- Page Header Band:
- Page Header-এ আপনি কোম্পানির নাম, লোগো, পেজ নম্বর বা অন্য কোনো স্থির তথ্য প্রদর্শন করতে পারেন।
- উদাহরণে, Company XYZ নামটি pageHeader band-এ রয়েছে, এবং পেজ নম্বরও এখানে প্রদর্শিত হয়েছে।
- Detail Band:
- Detail band হল রিপোর্টের প্রধান অংশ, যেখানে ডেটা প্রদর্শিত হয়। সাধারণত, এই band-এ database থেকে আসা ডেটা থাকে, যেমন Employee Name, Age, এবং Salary।
- এই অংশটি ডেটা সোর্স (JDBC, Collection, etc.) এর প্রতিটি রেকর্ডকে JSON বা টেবিল আকারে প্রদর্শন করে।
- Summary Band:
- Summary band সাধারণত রিপোর্টের শেষে আসে এবং কোনো উপসংহার বা সারাংশ প্রদান করে। এটি ঐ রিপোর্টটির শেষ অংশ হিসেবে ব্যবহার করা হয়।
- এই উদাহরণে, End of Report বার্তা summary band-এ আছে।
- Page Footer Band:
- Page Footer একটি পেজের নিচের অংশে থাকে, এবং সাধারণত পেজ নম্বর বা অন্য তথ্য প্রকাশ করতে ব্যবহৃত হয়।
- এখানে, পেজ নম্বর প্রদর্শিত হচ্ছে pageFooter band-এ।
Step 2: JasperReports Template Compilation and Report Generation
এখন যে JRXML ফাইল তৈরি করা হয়েছে, সেটি Java Code দিয়ে কম্পাইল করা এবং রিপোর্ট তৈরি করা হবে। নিচে এক্সামপল কোড দেওয়া হল:
Java Code for Report Generation:
import net.sf.jasperreports.engine.*;
import java.util.HashMap;
import java.util.Map;
public class ReportGeneration {
public static void main(String[] args) {
try {
// Compile JRXML to Jasper Report
JasperReport jasperReport = JasperCompileManager.compileReport("example_report.jrxml");
// Parameters to be passed to the report
Map<String, Object> parameters = new HashMap<>();
parameters.put("ReportTitle", "Employee Report");
// Fill the report with data (Here we use an empty data source for demonstration)
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, parameters, new JREmptyDataSource());
// Export the report to a PDF file
JasperExportManager.exportReportToPdfFile(jasperPrint, "EmployeeReport.pdf");
// Optionally, view the report in a viewer
JasperViewer.viewReport(jasperPrint, false);
System.out.println("Report generated successfully!");
} catch (JRException e) {
e.printStackTrace();
}
}
}
Report Output:
- এই কোডটি JRXML ফাইল থেকে একটি JasperReport তৈরি করে এবং রিপোর্টটিকে PDF আকারে রপ্তানি করে।
- আপনি JasperViewer ব্যবহার করে রিপোর্টটি দেখতে পারেন।
- JasperReports-এ বিভিন্ন bands (Title, PageHeader, Detail, Summary, PageFooter) ব্যবহার করে রিপোর্টের কাঠামো তৈরি করা যায়।
- প্রতিটি band রিপোর্টের নির্দিষ্ট অংশ পরিচালনা করে, যেমন title ফিল্ডে শিরোনাম, detail band-এ ডেটা প্রদর্শন, summary-এ উপসংহার, এবং footer-এ পেজ নম্বর।
- আপনি আপনার রিপোর্টের জন্য কাস্টম ডিজাইন এবং লেআউট তৈরি করতে এই bands ব্যবহার করতে পারেন।
Content added By
Read more