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());
}