DEV Community

Discussion on: JXLS: How to generate Excel documents using templates?

Collapse
 
drvicx profile image
Victor Nuzhdin • Edited

I found solution. Maybe useful for someone
//--step1: create intermediate stream
ByteArrayOutputStream jxlsOutStream = new ByteArrayOutputStream();
//--step2: call create Excel stream method and write result to jxlsOutStream
report.createDocument(jxlsOutStream, templateName, data);
//--step3: create HTTPServletResponse output stream
ServletOutputStream outputStream = response.getOutputStream();
//--step4: convert ByteArrayOutputStream to InputStream
byte[] bytes = jxlsOutStream.toByteArray();
InputStream inputStream = new ByteArrayInputStream(bytes);
//--step5: copy data from InputStream to OutputStream data types
IOUtils.copy(inputStream, outputStream);
//--step6: now we have JXLS streaming data in HttpServletResponse
public void getJXLSStream(HttpServletResponse response) {..}

..thanks to Me))