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 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
|
public class LaunchReporting6Action extends AbstractAction {
public ActionForward doAction(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) {
try {
User user = getConnectedUser(request);
String uid = user.getUidUtilisateur();
String idProprietaire = "55";
//remplissage de la table du rapport
getServiceLocator().getEReportReportingService().fillTablereport6(uid, idProprietaire);
Map parameters = new HashMap();
parameters.put("TITRE", "RAPPORT_6");
parameters.put("SOUS_TITRE", "test sous-titre");
// chargement du template
InputStream reportStream = this.getClass().getClassLoader().getResourceAsStream("bnppi/ereport/jasperreports/report6.jasper");
// chargement de la data source XML
InputStream dataSourceStream = this.getClass().getClassLoader().getResourceAsStream("bnppi/ereport/jasperreports/JasperTestDatasource.xml");
JasperReport jasperReport = (JasperReport) JRLoader.loadObject(reportStream);
JRXmlDataSource ds = new JRXmlDataSource(dataSourceStream, "/data/*");
JRResultSetDataSource ds_rs = new JRResultSetDataSource(getServiceLocator().getEReportReportingService().dataTableEreport6(uid));
// remplissage du rapport avec les données du datasource
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, parameters, ds);
// export sous format excel dans un OutputStream
JRXlsExporter exporter = new JRXlsExporter();
ByteArrayOutputStream baos = new java.io.ByteArrayOutputStream();
exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, baos);
exporter.setParameter(JRXlsExporterParameter.IS_ONE_PAGE_PER_SHEET, Boolean.FALSE);
exporter.setParameter(JRXlsExporterParameter.IS_WHITE_PAGE_BACKGROUND, Boolean.FALSE);
exporter.setParameter(JRXlsExporterParameter.IS_IGNORE_CELL_BORDER,
Boolean.TRUE);
exporter.setParameter(JRXlsExporterParameter.IS_COLLAPSE_ROW_SPAN,
Boolean.TRUE);
exporter.exportReport();
// interception du résultat pour la mise en forme
byte[] excelFile = baos.toByteArray();
HSSFWorkbook wkb = new HSSFWorkbook(new ByteArrayInputStream(excelFile));
HSSFSheet sheet = wkb.getSheetAt(0);
sheet.createFreezePane(0, 3);
// sheet.groupRow((short) 5, (short) 7);
response.reset();
response.setContentType("application/excel");
response.setHeader("content-disposition", "attachment; filename=reporting6.xls");
wkb.write(response.getOutputStream());
} catch (IOException e) {
throw convertSystemException(e);
} catch (JRException e) {
throw convertSystemException(e);
}
return null;
}
} |
Partager