随笔 - 6  文章 - 129  trackbacks - 0
<2024年12月>
24252627282930
1234567
891011121314
15161718192021
22232425262728
2930311234

常用链接

留言簿(14)

随笔档案(6)

文章分类(467)

文章档案(423)

相册

收藏夹(18)

JAVA

搜索

  •  

积分与排名

  • 积分 - 822216
  • 排名 - 49

最新评论

阅读排行榜

评论排行榜

部分代码如下(POI的版本为3.2)
public void insertRow() throws IOException {

      POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream("workbook.xls"));
       HSSFWorkbook wb = new HSSFWorkbook(fs);
       HSSFSheet sheet = wb.getSheet("new sheet");
      int starRow = 4;
      int rows = 5;
     
        sheet.shiftRows(starRow + 1, sheet.getLastRowNum(), rows,true,false);
        //Parameters:
        //startRow - the row to start shifting
        //endRow - the row to end shifting
        //n - the number of rows to shift
        //copyRowHeight - whether to copy the row height during the shift
        //resetOriginalRowHeight - whether to set the original row's height to the default
      
        starRow = starRow - 1;

        for (int i = 0; i < rows; i++) {
         HSSFRow sourceRow = null;
         HSSFRow targetRow = null;
         HSSFCell sourceCell = null;
         HSSFCell targetCell = null;
         short m;
         starRow = starRow + 1;
         sourceRow = sheet.getRow(starRow);
         targetRow = sheet.createRow(starRow + 1);
         targetRow.setHeight(sourceRow.getHeight());
 
         for (m = sourceRow.getFirstCellNum(); m < sourceRow.getLastCellNum(); m++) {
         sourceCell = sourceRow.getCell(m);
         targetCell = targetRow.createCell(m);
 
         //targetCell.setEncoding(sourceCell.getEncoding());
         targetCell.setCellStyle(sourceCell.getCellStyle());
         targetCell.setCellType(sourceCell.getCellType());
         targetCell.setCellValue(i);//設置值
         }
       }
     FileOutputStream fileOut = new FileOutputStream("workbook.xls");
        wb.write(fileOut);
        fileOut.close();
   }

参考了http://blog.csdn.net/daemon_boy/archive/2007/09/15/1786384.aspx的代码

posted on 2009-04-16 16:43 Ke 阅读(10803) 评论(0)  编辑  收藏 所属分类: java excel

只有注册用户登录后才能发表评论。


网站导航: