net.ibizsys.central.plugin.jr.util.JasperReportUtils Maven / Gradle / Ivy
package net.ibizsys.central.plugin.jr.util;
import java.io.OutputStream;
import java.util.List;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.export.HtmlExporter;
import net.sf.jasperreports.engine.export.JRPdfExporter;
import net.sf.jasperreports.engine.export.JRXlsExporter;
import net.sf.jasperreports.export.Exporter;
import net.sf.jasperreports.export.SimpleExporterInput;
import net.sf.jasperreports.export.SimpleOutputStreamExporterOutput;
/**
* JasperReport 辅助功能对象
* @author lionlau
*
*/
public class JasperReportUtils {
private static final org.apache.commons.logging.Log log = org.apache.commons.logging.LogFactory.getLog(JasperReportUtils.class);
public static void output(OutputStream outputStream, List jasperPrintList, String strType) throws Exception{
try {
@SuppressWarnings("rawtypes")
Exporter exporter;
if(IJasperReportRuntime.CONTENTTYPE_PDF.equals(strType)) {
exporter = new JRPdfExporter();
}
else
if(IJasperReportRuntime.CONTENTTYPE_EXCEL.equals(strType)) {
exporter = new JRXlsExporter();
}
else
if(IJasperReportRuntime.CONTENTTYPE_HTML.equals(strType)) {
exporter = new HtmlExporter();
}
else {
exporter = new JRPdfExporter();
}
exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(outputStream));
exporter.setExporterInput(SimpleExporterInput.getInstance(jasperPrintList));
exporter.exportReport();
} catch (Exception ex) {
log.error(String.format("导出报表发生异常,%1$s", ex.getMessage()), ex);
throw ex;
}
}
}