Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Lotus notes 如何从浏览器将Excel文件保存到本地驱动器_Lotus Notes_Xpages - Fatal编程技术网

Lotus notes 如何从浏览器将Excel文件保存到本地驱动器

Lotus notes 如何从浏览器将Excel文件保存到本地驱动器,lotus-notes,xpages,Lotus Notes,Xpages,我有一个XPage,它使用服务器端javascript创建Excel文件(感谢Russ Maher)。如果我在浏览器中本地运行XPage,我知道如何将其保存到C:drive,但如果它在服务器上运行,我不知道如何将其保存到用户的计算机,而不首先将其保存到服务器。下面的代码用于从服务器的角度保存它 var fileOut = new java.io.FileOutputStream(directory+fileName); xl.write(fileOut); fileOut.close(); 您

我有一个XPage,它使用服务器端javascript创建Excel文件(感谢Russ Maher)。如果我在浏览器中本地运行XPage,我知道如何将其保存到C:drive,但如果它在服务器上运行,我不知道如何将其保存到用户的计算机,而不首先将其保存到服务器。下面的代码用于从服务器的角度保存它

var fileOut = new java.io.FileOutputStream(directory+fileName);
xl.write(fileOut);
fileOut.close();

您知道如何将其定向到用户的驱动器吗?

与其将Excel工作簿写入FileOutputStream,不如将其写入ByteArrayOutputStream:

ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
xl.write(outputStream);

您可能需要使用XAgent来创建输出,然后从XPage链接到XAgent。也许与结合可以指导您走向正确的方向。

保罗·卡尔霍恩(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();

如果有人遇到这个问题,我会很乐意提供帮助,希望在有人提出问题时,我能更多地了解起作用的不同之处……

Per是正确的。查看OpenNTF上XSnippets中的XAgent代码段。它提供输出流。因此,不要创建自己的流,而是将其作为参数传递给方法。然后,内容处置标头可以确定文件名。请记住,用户需要确认保存。此外,还可以查看ApachePOI,了解更高级的Excel输出功能。Per的Hanks将对此进行检查@我正在使用ApachePOI,但我是一个真正的业余爱好者,刚刚接受了RussMaher的实现并对其进行了一些扩展。