2012-09-28 135 views
0

我必须从导出大量数据(> 100000个文档)。 对于此功能,我使用java apache poi,但服务器在4-5000对话后崩溃。
无法安装在服务器上。
格式不是一个选项。
使用预定义的有限数量的记录创建更多文件不是​​一种选择。
什么是导出视图中所有文档中每个字段的正确方法/技术? 从Lotus导出到MS EXCEL


var maxDocs:Integer = 6001;

function ExcExp(docIDArray:Array, sVieNam:String, proFie, filTip:String,logEve:String){ 
var sUzenet='xpExcel ExcExp '; 
var bRetVal=false; 
var docId:String; 
var doc:NotesDocument=null; 
var tmpDoc:NotesDocument=null; 
var aIteNam:array=new Array(); 
var aIteLab:array=new Array(); 
var aIteHin:array=new Array(); 
var sIteNam:String; 
var category:String; 
var y=0; 
[email protected](proFie.getString('fieNam'),'~'); 
[email protected](proFie.getString('fieLab'),'~'); 
[email protected](proFie.getString('fieHin'),'~'); 
var rowInd=new java.lang.Integer(0); 
var rowInd1=new java.lang.Integer(3); 
try{ 
var fileName='c:\\Temp\\'+renFile('_'+filTip+'_','xls');  
var fileOut = new java.io.FileOutputStream(fileName); 
var wb = new org.apache.poi.hssf.usermodel.HSSFWorkbook(); 
var sheet=wb.createSheet('CRM'+filTip+'Export'); 
var createHelper = wb.getCreationHelper(); 
var drawing = sheet.createDrawingPatriarch(); 
var anchor = createHelper.createClientAnchor(); 
var row=sheet.createRow(rowInd);   
for (x=0;x<aIteNam.length;x++){ 
cellInd=new java.lang.Integer(x); 
colInd1=new java.lang.Integer(x); 
colInd2=new java.lang.Integer(x+5); 
var cell=row.createCell(cellInd); 
cell.setCellValue(aIteNam[cellInd]); 
anchor.setCol1(colInd1); 
anchor.setCol2(colInd2); 
anchor.setRow1(rowInd); 
anchor.setRow2(rowInd1); 
var comment = drawing.createCellComment(anchor); 
var str = createHelper.createRichTextString(aIteLab[cellInd]+": "+fieldHint.getString(aIteHin[cellInd])); 
comment.setString(str); 
comment.setAuthor(@Name('[Abbreviate]',@UserName())); 
cell.setCellComment(comment);   
} 
for (x=0;x<aIteNam.length;x++){ 
cellInd=new java.lang.Integer(x); 
sheet.autoSizeColumn(cellInd);   
} 
if (docIDArray.length>0){ 
for(y=0;y<docIDArray.length;y++){ 
docId=docIDArray[y]; 
doc=database.getDocumentByID(docId); 
if (doc!=null){       
bRetVal=false; 
rowInd=new java.lang.Integer(y+1); 
row=sheet.createRow(rowInd);  
for (x=0;x<aIteNam.length;x++){ 
cellInd=new java.lang.Integer(x);      
cell=row.createCell(cellInd); 
sIteNam=aIteNam[cellInd]; 
if (doc.hasItem(sIteNam)){ 
if (doc.getFirstItem(sIteNam).getType()!=1){ 
cell.setCellValue(doc.getItemValueString(sIteNam)); 
}else{ 
cell.setCellValue(doc.getFirstItem(sIteNam).getFormattedText(true, 0,0)); 
} 
}else{ 
cell.setCellValue(''); 
} 
} 
bRetVal=true;  
if (bRetVal){  
} 
} 
for (x=0;x<aIteNam.length;x++){ 
cellInd=new java.lang.Integer(x); 
sheet.autoSizeColumn(cellInd);   
} 
wb.write(fileOut);    
}else{ 
if (viewScope.query && viewScope.query.length>0){ 
bRetVal=false; 
var vView=database.getView(sVieNam); 
if (vView.FTSearch(viewScope.query,maxDocs)>0){    
doc=vView.getFirstDocument(); 
y=1; 
while (doc!=null && y<maxDocs){     
tmpDoc=vView.getNextDocument(doc); 
rowInd=new java.lang.Integer(y); 
row=sheet.createRow(rowInd); 
for (x=0;x<aIteNam.length;x++){       
cellInd=new java.lang.Integer(x);      
cell=row.createCell(cellInd); 
sIteNam=aIteNam[cellInd]; 
if (doc.hasItem(sIteNam)){ 
cell.setCellValue(doc.getItemValueString(sIteNam)); 
}else{ 
cell.setCellValue(''); 
} 
} 
bRetVal=true;  
doc.recycle(); 
doc=tmpDoc; 
y=y+1; 
} 
}    
for (x=0;x<aIteNam.length;x++){ 
cellInd=new java.lang.Integer(x); 
sheet.autoSizeColumn(cellInd);   
} 
wb.write(fileOut); 
}else{ 
bRetVal=false; 
var vView=database.getView(sVieNam); 
doc=vView.getFirstDocument(); 
var y=1; 
while (doc!=null && y<maxDocs){     
tmpDoc=vView.getNextDocument(doc); 
rowInd=new java.lang.Integer(y); 
row=sheet.createRow(rowInd); 
for (x=0;x<aIteNam.length;x++){       
cellInd=new java.lang.Integer(x);      
cell=row.createCell(cellInd); 
sIteNam=aIteNam[cellInd]; 
if (doc.hasItem(sIteNam)){ 
cell.setCellValue(doc.getItemValueString(sIteNam)); 
}else{ 
cell.setCellValue(''); 
} 
} 

bRetVal=true;  
doc.recycle(); 
doc=tmpDoc; 
y=y+1; 
}    
for (x=0;x<aIteNam.length;x++){ 
cellInd=new java.lang.Integer(x); 
sheet.autoSizeColumn(cellInd);   
} 
wb.write(fileOut); 
} 
}  
fileOut.close(); 
if (y>0){ 
doc=database.createDocument(); 
doc.replaceItemValue('Form','ExcelExport'); 
doc.replaceItemValue('From',@Name('[Abbreviate]',@UserName())); 
doc.replaceItemValue('Subject',logEve+' Export'); 
doc.replaceItemValue('Records',y);  
doc.replaceItemValue('categories',logEve); 
var rtitem:NotesRichTextItem = doc.createRichTextItem('Body'); 
rtitem.embedObject(NotesEmbeddedObject.EMBED_ATTACHMENT, fileName,fileName, null); doc.replaceItemValue('fileSize',doc.getFirstItem('Body').getEmbeddedObjects()[0].getFileSize()/1000); 
doc.save(); 
} 
delFile(fileName); 
}catch(e){ 
fileOut.close(); 
delFile(fileName); 
bRetVal=false;  
sUzenet+=' hiba: '+e; 
msgVScope(sUzenet); 
}finally{  
return bRetVal; 
} 
} 
+0

你回收对象为你处理它们?如果不是,这或许可以解释为什么服务器崩溃。 –

+0

我可循环利用,但是可能是错误的,我只需几分钟即可上传代码。 – jlehocz

+0

您可以向我们显示服务器返回的消息就在它崩溃之前?也许你还应该检查HTTP任务正在使用的内存。 – jjtbsomhorst

回答

1

正如意见建议:

  • 将所有代码托管bean。我建议你将profileDocument,数据库,会话和OutputStream传递给呈现电子表格的函数。通过这种方式,您可以在命令行或代理中使用该类,或直接在浏览器响应(XAgent样式)中传回工作表,该命令行对于调试实际上是无价的。
  • 观察变量并正确回收所有东西(检查OpenNTF上的Shred(base ... moreturi)函数
  • 除非您确实想要在浏览器中传回电子表格....使用代理(与豆的方法,你可以改变你的想法随时)

让我们知道如何去