我想使用xagent原理使用Apache Poi從Notes視圖創建導出。如何用「xagent」創建多個導出?
但是,而不是1導出的文件與多個工作表我想創建多個導出,每個只包含1張工作表。
可能嗎?例如
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();
您認爲這應該如何運作?一個HTTP請求應該用多個響應來應答,每個響應包含一個文件?不,這不會使用HTTP。或者一個HTTP請求應該回答一個包含多個文件的響應?這可以使用HTTP。只需發送響應主體中所有文件的字節。但操作系統如何分離文件?使用包含工作簿文件的ZIP存檔(一個文件)將是唯一的選擇。 –
@AxelRichter我知道這聽起來不是邏輯,但如果你碰巧知道解決方法。當然,我可以在後端創建文檔,並將它們存儲在Notes文檔中... –