Today i need to write some code about import/export the excel by using poi,at first i find the addrow,createrow method,but didn't find insertrow method which was the most wonderful thing i'm looking for,i'm really dispointed.why apache projecters didn't realizate it. at last I found the shiftRows method instead,it's great.
if(baseIndex >3){
//auto move the rows
sheetArrays[index].shiftRows(19+baseIndex, rowNum+intFileRowNum, 1,true,false);
row = sheetArrays[index].createRow(19+baseIndex);
for(int i=0;i<7;i++){
cell = row.createCell((short)i);
cell.setCellStyle(getDataStyle(recordWorkbook,HSSFCellStyle.ALIGN_LEFT));
if(i == 1){
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue(1+baseIndex);
cell.setCellStyle(getDataStyle(recordWorkbook,HSSFCellStyle.ALIGN_CENTER));
}else if(i==2){
AjTBaseFile ajTBaseFile=(AjTBaseFile)baseFileList.get(baseIndex);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue(ajTBaseFile.getfile_name());
}
}
row.setHeight((short)440);
sheetArrays[index].addMergedRegion(new Region(19,(short)0,19+baseIndex,(short)0));
sheetArrays[index].addMergedRegion(new Region(19+baseIndex,(short)2,19+baseIndex,(short)6));
intFileRowNum += 1;
}else{
row = sheetArrays[index].getRow(19+baseIndex);
AjTBaseFile ajTBaseFile=(AjTBaseFile)baseFileList.get(baseIndex);
cell = row.getCell((short)2);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue(ajTBaseFile.getfile_name());
}
使用POI插行技巧
本文介绍了使用Apache POI库处理Excel文件时的一种实用方法——通过shiftRows方法来实现插入行的功能,因为POI并未直接提供insertRow方法。文中详细展示了如何通过移动已有行并创建新行来达到在指定位置插入行的目的。
2622

被折叠的 条评论
为什么被折叠?



