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

          常用鏈接

          留言簿(14)

          隨筆檔案(6)

          文章分類(467)

          文章檔案(423)

          相冊

          收藏夾(18)

          JAVA

          搜索

          •  

          積分與排名

          • 積分 - 827218
          • 排名 - 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

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


          網站導航:
           
          主站蜘蛛池模板: 开封县| 和林格尔县| 南丰县| 宜兰县| 盈江县| 五台县| 宜州市| 榆树市| 张家川| 屏南县| 清涧县| 吴忠市| 瓮安县| 红桥区| 双辽市| 湾仔区| 盈江县| 泰安市| 紫金县| 荔浦县| 全椒县| 镇赉县| 达日县| 岑溪市| 诏安县| 威信县| 奉化市| 祁阳县| 新巴尔虎右旗| 温宿县| 淮滨县| 隆尧县| 黑水县| 绍兴市| 兴义市| 灵石县| 福鼎市| 湖南省| 黄平县| 保靖县| 三台县|