[英]how to create multiple exports with “xagent”?
我想使用xagent原理使用Apache Poi從Notes視圖創建導出。
但是,我要創建多個導出,而不是一個包含多張圖紙的導出文件,每個導出只包含一張圖紙。
有可能嗎 例如
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();
問題不僅僅在於XPages或POI,而是對Web交互如何工作的基本理解。 您發送到任何服務器的每個請求都只有一個Stream返回數據。 可以使用附件標頭將該流重定向到文件。 它仍然是一條流。 因此,如果要在一個流中包含多個文件,則需要有一個可以容納該文件的流目標。 http協議沒有。 一個請求產生一個響應。 但是,您可以做的是將各個文件寫入zip文件,然后將其返回給請求。
更新但是您真正想要做的是:讓服務器端准備根據查詢字符串一次創建一個xls。 然后,在您要從中獲取文件的頁面中,分別對每個文件使用ajax請求,並使用html5文件api在本地寫回結果。 因此,您無需在服務器上解決此問題,而是將客戶端放在了駕駛員的座位上。 在那里,您可以顯示動畫,對每個完成情況做出反應等。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.