jasper

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();
}
}
}

posted @ 2015-10-15 11:59  丶下雨了  阅读(283)  评论(0编辑  收藏  举报