码迷,mamicode.com
首页 > Web开发 > 详细

jasper

时间:2015-10-15 12:40:25      阅读:156      评论:0      收藏:0      [点我收藏+]

标签:

package jasper;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JRExporterParameter;
import net.sf.jasperreports.engine.JasperExportManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource;
import net.sf.jasperreports.engine.export.JRXlsExporter;

public class JasperReportFill {
@SuppressWarnings("unchecked")
public static void main(String[] args) throws Exception {
String sourceFileName = "f://jaspertest/report1.jasper";
String printFileName = null;
DataBeanList DataBeanList = new DataBeanList();
ArrayList dataList = DataBeanList.getDataBeanList();
JRBeanCollectionDataSource beanColDataSource =
new JRBeanCollectionDataSource(dataList);

Map parameters = new HashMap();

try {
printFileName = JasperFillManager.fillReportToFile(sourceFileName,
parameters, beanColDataSource);
if (printFileName != null) {
/**
* 1- export to PDF
*/
JasperExportManager.exportReportToPdfFile(printFileName,
"f://sample_report.pdf");

/**
* 2- export to HTML
*/
JasperExportManager.exportReportToHtmlFile(printFileName,
"f://sample_report.html");

/**
* 3- export to Excel sheet
*/
// JRXlsExporter exporter = new JRXlsExporter();
//
// exporter.setParameter(JRExporterParameter.INPUT_FILE_NAME,
// printFileName);
// exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME,
// "f://sample_report.xls");
//
// exporter.exportReport();
}
} catch (JRException e) {
e.printStackTrace();
}
}
}

jasper

标签:

原文地址:http://www.cnblogs.com/rain-tl/p/4881989.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!