我正在尝试将我的xpages导出为excel。它涉及将阿拉伯语文本和数字导出为excel。
问题是当我在excel中查看导出列时(阿拉伯语中的客户端名称)。结果是垃圾。
我的Lotus数据库配置为支持英语和阿拉伯语,编码为utf-8
非常欢迎任何帮助。
这是我正在使用的代码。
var exCon = facesContext.getExternalContext();
var writer = facesContext.getResponseWriter();
var response = exCon.getResponse();
docIDArray=sessionScope.selectedDocs;
//lets define domino classess
var myView:NotesView = database.getView(sessionScope.vname);
response.setContentType("application/vnd.ms-excel;charset=utf-8");
response.setHeader("Cache-Control", "no-cache");
response.setHeader("Content-disposition", "attachment; filename=CustomerCare.xls");
writer.write("<table>");
writer.write("<thead><tr>");
writer.write("<td><b>Created</b></td>");
writer.write("<td><b>Client Name</b></td>");
writer.write("<td><b>Daybreak ID</b></td>");
writer.write("<td><b>Request type</b></td>");
writer.write("<td><b>Status</b></td>");
writer.write("<td><b>Mobile #</b></td>");
writer.write("<td><b>Escalation</b></td>");
writer.write("<td><b>Request via</b></td>");
writer.write("<td><b>From</b></td>");
writer.write("<td><b>Updated by</b></td>");
writer.write("</tr></thead>");
/**
debuggin purpose only
print(sessionScope.vname+'-viewname');
print(sessionScope.selectedDocs+' -selectedDocs');
print(sessionScope.vfilter+'-vfilter' );
print(sessionScope.catFilter+'-catFilter');
**/
//determine if user wants to export all or the individual documents
//export all document in current display/view
if (docIDArray.length==0){
//since some view are special evaluate them here
switch(sessionScope.vname)
{
case "Status":
var dc:NotesDocumentCollection=myView.getAllDocumentsByKey(sessionScope.vfilter);
var doc:NotesDocument=dc.getFirstDocument();
while (doc!= null){
writer.write("<tr>");
writer.write("<td>" + doc.getItemValueDateTimeArray("dxdateFiled").elementAt(0)+ "</td>");
writer.write("<td>" + doc.getItemValueString("cxClientName")+ "</td>");
writer.write("<td>" + doc.getItemValueString("cxDBID") + "</td>");
writer.write("<td>" + @Implode(doc.getItemValueString("cxStatus_1"),",") + "</td>");
//writer.write("<td>" + doc.getItemValueString("cxStatus_1") + "</td>");
writer.write("<td>" + doc.getItemValueString("cxStatus1") + "</td>");
writer.write("<td>" + doc.getItemValueString("cxMobile") + "</td>");
if(doc.getItemValue("escalationlevel").toString()=='[3.0]'){
writer.write("<td>" + '3' + "</td>");
}else{
writer.write("<td>" + '-' + "</td>");
}
writer.write("<td>" + doc.getItemValueString("cxRecRequestvia") + "</td>");
writer.write("<td>" + doc.getItemValueString("From")+ "</td>");
writer.write("<td>" + doc.getItemValueString("Closedby") + "</td>");
writer.write("</tr>");
doc=dc.getNextDocument(doc);
}
break;
case "Categories":
case "callStatus":
var sString:String = sessionScope.catFilter;
var viewNav:NotesViewNavigator = myView.createViewNavFromCategory(sString);
var viewEnt:NotesViewEntry = viewNav.getFirst();
while (viewEnt!=null){
writer.write("<tr>");
writer.write("<td>" + viewEnt.getColumnValues()[2] + "</td>");
writer.write("<td>" + viewEnt.getColumnValues()[3] + "</td>");
writer.write("<td>" + viewEnt.getColumnValues()[5] + "</td>");
writer.write("<td>" + viewEnt.getColumnValues()[7].toString() + "</td>");
writer.write("<td>" + viewEnt.getColumnValues()[8] + "</td>");
writer.write("<td>" + viewEnt.getColumnValues()[9] + "</td>");
if( viewEnt.getColumnValues()[6].toString()=='3'){
writer.write("<td>" + '3' + "</td>");
}else{
writer.write("<td>" + '-' + "</td>");
}
writer.write("<td>" + viewEnt.getColumnValues()[10] + "</td>");
writer.write("<td>" + viewEnt.getColumnValues()[1] + "</td>");
writer.write("<td>" + viewEnt.getColumnValues()[11] + "</td>");
writer.write("</tr>");
viewEnt = viewNav.getNext(viewEnt);
}
break;
default:
var viewNav:NotesViewNavigator = myView.createViewNav();
var viewEnt:NotesViewEntry = viewNav.getFirst();
while (viewEnt!=null){
writer.write("<tr>");
writer.write("<td>" + viewEnt.getColumnValues()[2] + "</td>");
writer.write("<td>" + viewEnt.getColumnValues()[3] + "</td>");
writer.write("<td>" + viewEnt.getColumnValues()[5] + "</td>");
writer.write("<td>" + viewEnt.getColumnValues()[7].toString() + "</td>");
writer.write("<td>" + viewEnt.getColumnValues()[8] + "</td>");
writer.write("<td>" + viewEnt.getColumnValues()[9] + "</td>");
if( viewEnt.getColumnValues()[6].toString()=='3'){
writer.write("<td>" + '3' + "</td>");
}else{
writer.write("<td>" + '-' + "</td>");
}
writer.write("<td>" + viewEnt.getColumnValues()[10] + "</td>");
writer.write("<td>" + viewEnt.getColumnValues()[1] + "</td>");
writer.write("<td>" + viewEnt.getColumnValues()[11] + "</td>");
writer.write("</tr>");
viewEnt = viewNav.getNext(viewEnt);
}
}
}else{
var db:NotesDatabase = session.getCurrentDatabase();
switch(sessionScope.vname)
{
case "Status":
for(i=0;i < docIDArray.length;i++){
var docId=docIDArray[i];
var doc:NotesDocument=db.getDocumentByID(docId);
var output:string = "";
if(doc != null) {
writer.write("<tr>");
writer.write("<td>" + doc.getItemValueDateTimeArray("dxdateFiled").elementAt(0)+ "</td>");
writer.write("<td>" + doc.getItemValueString("cxClientName")+ "</td>");
writer.write("<td>" + doc.getItemValueString("cxDBID") + "</td>");
writer.write("<td>" + doc.getItemValueString("cxStatus_1") + "</td>");
writer.write("<td>" + doc.getItemValueString("cxStatus1") + "</td>");
writer.write("<td>" + doc.getItemValueString("cxMobile") + "</td>");
if(doc.getItemValue("escalationlevel").toString()=='[3.0]'){
writer.write("<td>" + '3' + "</td>");
}else{
writer.write("<td>" + '-' + "</td>");
}
writer.write("<td>" + doc.getItemValueString("cxRecRequestvia") + "</td>");
writer.write("<td>" + doc.getItemValueString("cxUsername") + "</td>");
writer.write("<td>" + doc.getItemValueString("Closedby") + "</td>");
writer.write("</tr>");
} // end if
}//end for
break;
default:
for(i=0;i < docIDArray.length;i++){
var docId=docIDArray[i];
var doc:NotesDocument=db.getDocumentByID(docId);
var output:string = "";
if(doc != null) {
writer.write("<tr>");
writer.write("<td>" + doc.getItemValueDateTimeArray("dxdateFiled").elementAt(0)+ "</td>");
writer.write("<td>" + doc.getItemValueString("cxClientName")+ "</td>");
writer.write("<td>" + doc.getItemValueString("cxDBID") + "</td>");
writer.write("<td>" + doc.getItemValueString("cxStatus_1") + "</td>");
writer.write("<td>" + doc.getItemValueString("cxStatus1") + "</td>");
writer.write("<td>" + doc.getItemValueString("cxMobile") + "</td>");
if(doc.getItemValue("escalationlevel").toString()=='[3.0]'){
writer.write("<td>" + '3' + "</td>");
}else{
writer.write("<td>" + '-' + "</td>");
}
writer.write("<td>" + doc.getItemValueString("cxRecRequestvia") + "</td>");
writer.write("<td>" + doc.getItemValueString("cxUsername") + "</td>");
writer.write("<td>" + doc.getItemValueString("Closedby") + "</td>");
writer.write("</tr>");
} // end if
}//end for
}
}
writer.write("</table>");
writer.endDocument();
facesContext.responseComplete();
答案 0 :(得分:2)
我建议查看Apache POI。它可能已经解决了您遇到的问题并且也被更广泛地使用。用于创建Excel电子表格的API非常直观,特别是如果您在LotusScript中执行过类似的操作。
您目前使用的方法会向使用最新版本的MS Office的用户发出安全警告(它对于Web开发和MS Office是通用的,并非特定于XPage)。 Apache POI也意味着你不会收到这些警告。