隨筆 - 6  文章 - 129  trackbacks - 0
          <2025年6月>
          25262728293031
          1234567
          891011121314
          15161718192021
          22232425262728
          293012345

          常用鏈接

          留言簿(14)

          隨筆檔案(6)

          文章分類(467)

          文章檔案(423)

          相冊

          收藏夾(18)

          JAVA

          搜索

          •  

          積分與排名

          • 積分 - 827240
          • 排名 - 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 閱讀(10813) 評論(0)  編輯  收藏 所屬分類: java excel

          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 黄冈市| 凌云县| 柯坪县| 溧阳市| 吉木乃县| 新昌县| 湟中县| 宁都县| 武胜县| 鄂托克旗| 怀化市| 拉萨市| 儋州市| 库尔勒市| 东海县| 凌源市| 星子县| 闸北区| 东辽县| 报价| 临沧市| 惠州市| 商河县| 科技| 白河县| 阳信县| 吉水县| 论坛| 巨野县| 手游| 姜堰市| 长宁县| 周宁县| 白沙| 射洪县| 博野县| 东乡县| 汝城县| 景宁| 吉林省| 柳河县|