Have used SXSSFWorkbook in excel file creation & downloading after clicking a button. Below is the java code snippet.
try (ByteArrayOutputStream outByteStream = new ByteArrayOutputStream();
SXSSFWorkbook workbook = new SXSSFWorkbook();) {
workbook.write(outByteStream);
byte[] outArray = outByteStream.toByteArray();
response.setContentType("application/vnd.openxmlformats- officedocument.spreadsheetml.sheet");
response.setContentLength(outArray.length);
response.setHeader("Expires","0");
response.setHeader("Content-disposition","attachment; filename=xyz.xlsx");
try(OutputStream os=response.getOutputStream();) {
os.write(outArray);
os.flush();
} catch(Exception exp) {
throw exp;
}
} catch(Exception exp) {
throw exp;
}
Dependency in pom.xml
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.17</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.17</version>
</dependency>
I am getting “The site can’t be reached” issue after clicking the button. One beauty is that if we have large datasets; am not getting the issue. But for smaller, I am getting the issue. Please assist in correction for successful download.
Have tried putting try with resources for the fix & changed the content type. Still the issue comes.