1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
| public Response ListeAction(final MultivaluedMap<String, String> searchForm) throws EngineException,
UnsupportedEncodingException {
final ParamSyntheseListeActionDto syntheseListeActionDto = birtService
.mapFormToParamSyntheseListeAction(searchForm);
final ByteArrayOutputStream output = new ByteArrayOutputStream();
final BufferedOutputStream out = new BufferedOutputStream(output);
try {
// report engine
final BirtEngineFactory bef = BirtEngineFactory.getInstance();
final IReportEngine birtEngine = bef.getObject();
// déclaration du rapport
IReportRunnable runnable = null;
final Resource[] schemaLocation = new PathMatchingResourcePatternResolver()
.getResources("classpath:/birtsample/listeActionV2.rptdesign");
if (schemaLocation != null && schemaLocation.length > 0) {
// ouverture du rapport et création d'une nouvelle tache
runnable = birtEngine.openReportDesign(schemaLocation[0].getInputStream());
final IRunAndRenderTask runAndRenderTask = birtEngine.createRunAndRenderTask(runnable);
....
....
runAndRenderTask.setParameterValue("RparamTitreSynthese", titre_synthese);
final EXCELRenderOption xlsOptions = new EXCELRenderOption(options);
xlsOptions.setOutputFormat("xls");
xlsOptions.setOption(IExcelRenderOption.OFFICE_VERSION, "office2003");
runAndRenderTask.setRenderOption(xlsOptions);
xlsOptions.setOutputStream(out);
runAndRenderTask.run();
runAndRenderTask.close();
} catch (final Exception e) {
throw new WebApplicationException(e);
}
....
....
return Response.ok(output.toByteArray(), MediaType.APPLICATION_OCTET_STREAM)
.header("content-disposition", "attachment; filename = " + name + ext).build(); |
Partager