use of net.sf.jasperreports.engine.export.JRXlsExporter in project netxms by netxms.
the class FileSystemReportManager method renderResult.
@SuppressWarnings("rawtypes")
@Override
public File renderResult(UUID reportId, UUID jobId, ReportRenderFormat format) {
final File outputDirectory = getOutputDirectory(reportId);
final File dataFile = new File(outputDirectory, jobId.toString() + ".jrprint");
File outputFile = new File(outputDirectory, jobId.toString() + "." + System.currentTimeMillis() + ".render");
JRAbstractExporter exporter = null;
switch(format) {
case PDF:
exporter = new JRPdfExporter();
break;
case XLS:
exporter = new JRXlsExporter();
final JasperReport jasperReport = loadReport(reportId);
if (jasperReport != null) {
exporter.setParameter(JRXlsExporterParameter.SHEET_NAMES, new String[] { prepareXlsSheetName(jasperReport.getName()) });
}
exporter.setParameter(JRXlsExporterParameter.IS_IGNORE_CELL_BORDER, false);
exporter.setParameter(JRXlsExporterParameter.IS_WHITE_PAGE_BACKGROUND, false);
// Arrange cell spacing and remove paging gaps
exporter.setParameter(JRXlsExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_ROWS, true);
exporter.setParameter(JRXlsExporterParameter.IS_COLLAPSE_ROW_SPAN, true);
exporter.setParameter(JRXlsExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_COLUMNS, true);
exporter.setParameter(JRXlsExporterParameter.IS_ONE_PAGE_PER_SHEET, false);
exporter.setParameter(JRXlsExporterParameter.IS_DETECT_CELL_TYPE, true);
// Arrange graphics
exporter.setParameter(JRXlsExporterParameter.IS_IMAGE_BORDER_FIX_ENABLED, true);
exporter.setParameter(JRXlsExporterParameter.IS_FONT_SIZE_FIX_ENABLED, true);
exporter.setParameter(JRXlsExporterParameter.IS_IGNORE_GRAPHICS, false);
break;
default:
break;
}
exporter.setParameter(JRExporterParameter.INPUT_FILE, dataFile);
try {
exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, new FileOutputStream(outputFile));
exporter.exportReport();
} catch (Exception e) {
log.error("Failed to render report", e);
outputFile.delete();
outputFile = null;
}
return outputFile;
}
use of net.sf.jasperreports.engine.export.JRXlsExporter in project tutorials by eugenp.
the class JasperReportsXlsExporter method export.
/**
* Generates a ByteArrayOutputStream from the provided JasperReport using
* the {@link JRXlsExporter}. After that, the generated bytes array is
* written in the {@link HttpServletResponse}
*
* @param jp
* The generated JasperReport.
* @param fileName
* The fileName of the exported JasperReport
* @param response
* The HttpServletResponse where generated report has been
* written
* @throws JRException
* during JasperReport export.
* @throws IOException
* when writes the ByteArrayOutputStream into the
* HttpServletResponse
*/
@Override
public void export(JasperPrint jp, String fileName, HttpServletResponse response) throws JRException, IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
// Create a JRXlsExporter instance
JRXlsExporter exporter = new JRXlsExporter();
// Here we assign the parameters jp and baos to the exporter
exporter.setParameter(JRExporterParameter.JASPER_PRINT, jp);
exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, baos);
// Excel specific parameters
exporter.setParameter(JRXlsAbstractExporterParameter.IS_ONE_PAGE_PER_SHEET, Boolean.FALSE);
exporter.setParameter(JRXlsAbstractExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_ROWS, Boolean.TRUE);
exporter.setParameter(JRXlsAbstractExporterParameter.IS_WHITE_PAGE_BACKGROUND, Boolean.FALSE);
// Retrieve the exported report in PDF format
exporter.exportReport();
// Specifies the response header
response.setHeader("Content-Disposition", "inline; filename=" + fileName);
// Make sure to set the correct content type
// Each format has its own content type
response.setContentType("application/vnd.ms-excel");
response.setContentLength(baos.size());
// Retrieve the output stream
ServletOutputStream outputStream = response.getOutputStream();
// Write to the output stream
baos.writeTo(outputStream);
// Flush the stream
outputStream.flush();
}
use of net.sf.jasperreports.engine.export.JRXlsExporter in project dhis2-core by dhis2.
the class JRExportUtils method export.
/**
* Export the provided JasperPrint the format given by type.
*
* @param type the type to export to. XLS, PDF and HTML are supported.
* @param out the OutputStream to export to.
* @param jasperPrint the JasperPrint to export.
* @throws JRException on export failure.
*/
public static void export(String type, OutputStream out, JasperPrint jasperPrint) throws JRException {
if (TYPE_XLS.equals(type)) {
SimpleXlsReportConfiguration config = new SimpleXlsReportConfiguration();
config.setDetectCellType(true);
config.setRemoveEmptySpaceBetweenRows(true);
config.setRemoveEmptySpaceBetweenRows(true);
config.setCollapseRowSpan(true);
config.setWhitePageBackground(false);
JRXlsExporter exporter = new JRXlsExporter();
exporter.setExporterInput(new SimpleExporterInput(jasperPrint));
exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(out));
exporter.setConfiguration(config);
exporter.exportReport();
} else if (TYPE_PDF.equals(type)) {
JRPdfExporter exporter = new JRPdfExporter();
exporter.setExporterInput(new SimpleExporterInput(jasperPrint));
exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(out));
exporter.exportReport();
}
}
Aggregations