将数据从 Xpages 导出到 Excel 时行不明确

Ambiguous rows while exporting data from Xpages to Excel

当我将数据从视图导出到 Xpages 中的 excel 时,excel 的前几行仅显示尖括号,然后显示真实数据。下面是代码片段。

var exCon = facesContext.getExternalContext();
var writer = facesContext.getResponseWriter();
var response = exCon.getResponse();

response.setContentType("application/vnd.ms-excel");
response.setHeader("Cache-Control", "no-cache");
response.setHeader("Content-Disposition","attachment; filename=export.xls");

writer.write("<html>");
writer.write("<head>");
writer.write("<meta http-equiv=\"Content-Type\" content=\"text/html;charset=utf-8\"/>")
writer.write("</head>");
writer.write("<body>");
// set-up the table header
writer.write("<table>");
writer.write("<thead><tr>");

//Loop over view columns
var totalColumns = vwCurrent.getColumnCount();
for(var x=1;x<=totalColumns;x++) {
var column:NotesViewColumn = vwCurrent.getColumn(x);
writer.write("<td><b>" + column.getTitle() + "</b></td>");
}
writer.write("</tr></thead>");

// loop returned docs
var docCurrent:NotesDocument = vwCurrent.getFirstDocument();

//Variables for Multivalued Columns
var multiValueColSize = 0;
var multiValueColIndex = 1;  //Initialized to 1 as first value is just an indicator

while( null != docCurrent){
    var docNext:NotesDocument = vwCurrent.getNextDocument( docCurrent);

    // output data...
    writer.write("<tr>");
    // get columns, use view to format data ;-)
    var vectColumns:java.util.Vector = docCurrent.getColumnValues();
    for( intIndex = 0; intIndex < vectColumns.size(); intIndex++){
        var colValue = vectColumns.get( intIndex);
        /*Calculated columns*/
        switch(@Left(colValue,4)) {
        case "$PO$":
            var data = colValue.split(";");
            colValue = getStatusDate(data[1], data[2]);
            break;

        case "$MO$":
            var data = colValue.split(";");
            // Condition to ensure that, multivalued column with maximum size is set as multiValueColSize 
            if(multiValueColSize < data.length)
                multiValueColSize = data.length;
            //condition to ensure we do not get arrayindexOutofBond exception
            if (multiValueColIndex < data.length){  
                colValue = data[multiValueColIndex].split("##")[0];
            } else {
                colValue = "";
            }
            break; 
        }
        writer.write("<td>" + colValue + "</td>");
    }   
    writer.write("</tr>");

    if (multiValueColSize == 0 || ((multiValueColSize-1) == multiValueColIndex)){
        // re-assign next
        docCurrent.recycle();
        docCurrent = docNext;
        // Re-initialize variables for Multivalued Columns
        multiValueColSize = 0;
        multiValueColIndex = 1;
    } else {
        //increment the index by 1 to populate next values in the list
        multiValueColIndex = multiValueColIndex + 1;
    }
}

// close the table and the document
writer.write("</table>");

writer.write("<body>");
writer.write("</html>");
writer.endDocument()

我哪里做错了?有什么线索吗?

我会使用 openntf 上的 poi4xpages 项目,而不是尝试打印出 html excel 文件。 Excel的某些版本如果使用它会报错。

https://poi4xpages.openntf.org/

导致问题的是多值字段。当在视图中看到时,它被正确地用逗号分隔,但是当数据被写入 excel 时,同样导致了问题。因此,我在视图中使用了@Iplode,错误得到了解决。