/**
* 生成PDF
*
* @param srcPath 源报表模版文件
* @param destPath pdf报表文件
* @throws JRException
*/
private void pdf(final String srcPath, final String destPath) throws JRException
{
long start = System.currentTimeMillis();
File sourceFile = new File(srcPath);
JasperPrint jasperPrint = (JasperPrint) JRLoader.loadObject(sourceFile);
String destPdf = destPath + jasperPrint.getName() + ".pdf";
JasperExportManager.exportReportToPdfFile(jasperPrint, destPdf);
logger.debug("PDF creation time : {}", (System.currentTimeMillis() - start));
}
/**
* 生成xls
*
* @param srcPath 源报表模版文件
* @param destPath xls报表文件
* @throws JRException
*/
private void xls(final String srcPath, final String destPath) throws JRException
{
long start = System.currentTimeMillis();
File sourceFile = new File(srcPath);
JasperPrint jasperPrint = (JasperPrint) JRLoader.loadObject(sourceFile);
File destFile = new File(destPath, jasperPrint.getName() + ".xls");
JRXlsExporter exporter = new JRXlsExporter();
exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, destFile.toString());
exporter.setParameter(JRXlsExporterParameter.IS_ONE_PAGE_PER_SHEET, Boolean.FALSE);
exporter.exportReport();
logger.debug("XLS creation time : {}", (System.currentTimeMillis() - start));
}
/**
* 生成docx
*
* @param srcPath 源报表模版文件
* @param destPath docx报表文件
* @throws JRException
*/
private void docx(final String srcPath, final String destPath) throws JRException
{
long start = System.currentTimeMillis();
File sourceFile = new File(srcPath);
JasperPrint jasperPrint = (JasperPrint) JRLoader.loadObject(sourceFile);
File destFile = new File(destPath, jasperPrint.getName() + ".docx");
JRDocxExporter exporter = new JRDocxExporter();
exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, destFile.toString());
exporter.exportReport();
logger.debug("DOCX creation time : {}", (System.currentTimeMillis() - start));
}