Paul Calhoun 向我发送了一些示例代码,我对其进行了按摩以生成我想要的电子表格。我不知道他做了什么我没有做过的事情,但是,就目前而言,我认为这是解决方案的核心,只是利用 OutputStream 而不是 FileOutputStream 或 ByteArrayOutputStream。
// The Faces Context global object provides access to the servlet environment via the external content
var extCont = facesContext.getExternalContext();
// The servlet's response object provides control to the response object
var pageResponse = extCont.getResponse();
//Get the output stream to stream binary data
var pageOutput = pageResponse.getOutputStream();
// Set the content type and headers
pageResponse.setContentType("application/x-ms-excel");
pageResponse.setHeader("Cache-Control", "no-cache");
pageResponse.setHeader("Content-Disposition","inline; filename=" + fileName);
//Write the output, flush the buffer and close the stream
wb.write(pageOutput);
pageOutput.flush();
pageOutput.close();
// Terminate the request processing lifecycle.
facesContext.responseComplete();
如果其他人遇到此问题,我将很乐意提供帮助,并且希望在有人问的时候,我会更多地了解有什么不同之处......