Создание и архивирование нескольких файлов Xlsx в Zip-архив в Spring Boot Jasper Report - PullRequest
0 голосов
/ 03 июля 2019

Я создаю отчеты XLSX в SpringBoot с использованием Jasper Report, поэтому ранее я создавал и загружал отчеты XLSX с помощью HttpResponse (ответ).Но теперь я хочу сжать несколько файлов XLSX в Zip-файл, и этот zip-файл также должен загружаться с помощью функций HTTP response (response).Мой код xlsx приведен ниже:

JRBeanCollectionDataSource dataSource = new JRBeanCollectionDataSource(report);
// report is a HashMap List of Data collected from database

InputStream inputStream = this.getClass().getResourceAsStream("xyz.jrxml"); 

JasperReport jasperReport = JasperCompileManager.compileReport(inputStream);

JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, null, dataSource);   

final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();

JRXlsxExporter jrXlsxExporter = new JRXlsxExporter();

jrXlsxExporter.setExporterInput(new SimpleExporterInput(jasperPrint));

jrXlsxExporter.setExporterOutput(new SimpleOutputStreamExporterOutput(outputStream));

jrXlsxExporter.exportReport();
String fileName ="MyReport";

response.setHeader("Content-Disposition", "attachment; filename=" + fileName + ".xlsx");

response.setContentType("application/xlsx");

ServletOutputStream os = response.getOutputStream();

outputStream.writeTo(os);

os.flush();

Теперь я хочу использовать одни и те же функции response.setHeader и reponse.setContentType для добавления нескольких отчетов xlsx в ZIP-файл.

...