The problem looks old, the news is that I found working, but only with Firefox. That is the reason I put the question again. Any answer will be appreciated. Thanks!
The error message as below:
ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_DISPOSITION : getOutputStream() has already been called for this response
Cannot suppress a null exception. Self-suppression not permitted Fail to save: an error occurs while saving the package : The part /docProps/core.xml failed to be saved in the stream with marshaller.
The pom:
<dependency>
<groupId>org.apache.poi<groupId>
<artifactId>poi-ooxml<artifactId>
<version>5.1.0<version>
<dependency>
//controller
@Controller
@RequestMapping("/show")
public class ShowCPEController {
CPE cpe;
@Autowired
private CpeService cpeService;
@GetMapping("/export-to-excel")
public void exportIntoExcelFile(HttpServletResponse response) throws IOException {
response.setContentType("application/octet-stream");
DateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd_HH:mm:ss");
String currentDateTime = dateFormatter.format(new Date());
String headerKey = "Content-Disposition";
String headerValue = "attachment; filename=CPE, "+mainProiect.getBuilding().getTitular()+ currentDateTime + ".xlsx";
response.setHeader(headerKey, headerValue);
List <CPE> listOfCpe = cpeService.findAll();
cpe = cpeService.findByProject(mainProiect.getProjectId());
mainProiect.setCpe(cpe);
CPEtoExcelGenerator generator = new CPEtoExcelGenerator();
generator.generateExcelFile(response);
}
}
// excel class
public CPEtoExcelGenerator(){
workbook = new XSSFWorkbook();
}
public void generateExcelFile(HttpServletResponse response) throws IOException {
DefineSheet();
Line1_2();
Line5();
Line2127(23, "A", 2, A);
Line59();
Line62();
DrawHomeplate();
setBorders(CellRangeAddress.valueOf("B4:Ap6"), BorderStyle.THIN);
setBorders(CellRangeAddress.valueOf("B8:Ap8"), BorderStyle.THIN);
setBorders(CellRangeAddress.valueOf("A1:AP61"), BorderStyle.MEDIUM);
try (ServletOutputStream outputStream = response.getOutputStream()) {
workbook.write(outputStream);
workbook.close();
outputStream.flush();
outputStream.close();
} catch (IOException e) {
logger.log(Level.SEVERE, "excel ouput err: ", e);
}
}
put already,but posibble not in the correct place:
response.getOutputStream().close();
response.getOutputStream().flush();
Wish the app to work in any browser as well as with Firefox