简体   繁体   English

如何使用“ xagent”创建多个导出?

[英]how to create multiple exports with “xagent”?

I would like to use the xagent principle to create exports from Notes view using Apache Poi. 我想使用xagent原理使用Apache Poi从Notes视图创建导出。

But instead of 1 exported file with multiple sheets I would like to create multiple exports, each containing just 1 sheet. 但是,我要创建多个导出,而不是一个包含多张图纸的导出文件,每个导出只包含一张图纸。

Is possible? 有可能吗 eg 例如

importPackage(java.lang);
importPackage(org.apache.poi.hssf.usermodel);

var fieldList = sessionScope.fList;

var sheetName = "viewData";
var workbookName = "WBViewData";

var vName = sessionScope.viewName;
var nc: NotesView = database.getView(vName);
var doc: NotesDocument;
var ndoc: NotesDocument;

doc = nc.getFirstDocument();

for (d = 1; d <= nc.getEntryCount(); d++) {

    //Create a new workbook object from the poi library
    var wb: HSSFWorkbook = new HSSFWorkbook();
    //Create additional sheets using same syntax and different sheet name
    var sheet1: HSSFSheet = wb.createSheet(sheetName);

    //Create helper class and styles for dates
    var createHelper: HSSFCreationHelper = wb.getCreationHelper();
    var dateStyle: HSSFCellStyle = wb.createCellStyle();
    dateStyle.setDataFormat(HSSFDataFormat.getBuiltinFormat("m/d/yy"));

    var headerStyle: HSSFCellStyle = wb.createCellStyle();
    var headerFont: HSSFFont = wb.createFont();
    headerFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
    headerStyle.setFont(headerFont);

    //Create the Column Header Rows
    var row: HSSFRow = sheet1.createRow(0);
    for (i = 0; i <= fieldList.length - 1; i++) {

        var hCell: HSSFCell = row.createCell((java.lang.Integer)(i));
        hCell.setCellValue(fieldList[i]);
        hCell.setCellStyle(headerStyle);
    }

    var row: HSSFRow = sheet1.createRow(d);

    // process document...


    //Create the filename for the spreadsheet    
    var fileName = workbookName + ".xls";


    // 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();


    ndoc = nc.getNextDocument(doc);
    doc.recycle();
    doc = ndoc;
}

//  Terminate the request processing lifecycle.
facesContext.responseComplete();

The question is not so much about XPages or POI, but s fundamental understanding how web interaction works. 问题不仅仅在于XPages或POI,而是对Web交互如何工作的基本理解。 Each request you send to any server has exactly one Stream to return data. 您发送到任何服务器的每个请求都只有一个Stream返回数据。 That stream can be redirected to a file using the attachment header. 可以使用附件标头将该流重定向到文件。 It still is one stream. 它仍然是一条流。 So if you want to have multiple files in one stream, you need to have a stream destination that can accommodate that. 因此,如果要在一个流中包含多个文件,则需要有一个可以容纳该文件的流目标。 The http protocol doesn't. http协议没有。 One request yields one response. 一个请求产生一个响应。 What you can do however is writing your individual files into a zip file and return that one to the request. 但是,您可以做的是将各个文件写入zip文件,然后将其返回给请求。

Update But what you really want to do: have your server side ready to create one xls at a time based on a query string. 更新但是您真正想要做的是:让服务器端准备根据查询字符串一次创建一个xls。 Then in your page from where you want to grab the file you use an ajax request for each file separately and the html5 file api to write back the result locally. 然后,在您要从中获取文件的页面中,分别对每个文件使用ajax请求,并使用html5文件api在本地写回结果。 So instead of trying to solve this on the server, you put the client in the driver's seat. 因此,您无需在服务器上解决此问题,而是将客户端放在了驾驶员的座位上。 There you can show an animation, react on each completion etc. 在那里,您可以显示动画,对每个完成情况做出反应等。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM