简体   繁体   中英

how to create multiple exports with “xagent”?

I would like to use the xagent principle to create exports from Notes view using Apache Poi.

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. Each request you send to any server has exactly one Stream to return data. 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. 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.

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. 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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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