<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    love fish大鵬一曰同風(fēng)起,扶搖直上九萬里

    常用鏈接

    統(tǒng)計

    積分與排名

    friends

    link

    最新評論

    POI 復(fù)制excel一行到另外一個sheet頁(轉(zhuǎn))

    import java.io.FileInputStream;
    import java.io.FileNotFoundException;
    import java.io.FileOutputStream;
    import java.io.IOException;

    import org.apache.poi.hssf.usermodel.HSSFCell;
    import org.apache.poi.hssf.usermodel.HSSFRow;
    import org.apache.poi.hssf.usermodel.HSSFSheet;
    import org.apache.poi.hssf.usermodel.HSSFWorkbook;
    import org.apache.poi.hssf.util.Region;
    import org.apache.poi.poifs.filesystem.POIFSFileSystem;

    public class RowCopy {

     
    /**
      * 
    @param args
      * 
    @throws IOException
      * 
    @throws FileNotFoundException
      
    */


     @SuppressWarnings(
    "deprecation")
     
    public static void main(String[] args) {
      
    try {
       POIFSFileSystem fs 
    = new POIFSFileSystem(new FileInputStream(
         
    "exlsample.xls"));
       HSSFWorkbook wb 
    = new HSSFWorkbook(fs);

    //source ,target 為,源sheet 頁和目標(biāo)sheet頁,
       copyRows(wb, "source""target"3420);
       FileOutputStream fileOut 
    = new FileOutputStream("exlsample.xls");
       wb.write(fileOut);
       fileOut.flush();
       fileOut.close();
       System.out.println(
    "Operation finished");
      }
     catch (Exception e) {
       e.printStackTrace();
      }

     }


     
    public static void copyRows(HSSFWorkbook wb, String pSourceSheetName,
       String pTargetSheetName, 
    int pStartRow, int pEndRow, int pPosition) {
      HSSFRow sourceRow 
    = null;
      HSSFRow targetRow 
    = null;
      HSSFCell sourceCell 
    = null;
      HSSFCell targetCell 
    = null;
      HSSFSheet sourceSheet 
    = null;
      HSSFSheet targetSheet 
    = null;
      Region region 
    = null;
      
    int cType;
      
    int i;
      
    short j;
      
    int targetRowFrom;
      
    int targetRowTo;

      
    if ((pStartRow == -1|| (pEndRow == -1)) {
       
    return;
      }

      sourceSheet 
    = wb.getSheet(pSourceSheetName);
      targetSheet 
    = wb.getSheet(pTargetSheetName);
      
    // 拷貝合并的單元格
      for (i = 0; i < sourceSheet.getNumMergedRegions(); i++{
       region 
    = sourceSheet.getMergedRegionAt(i);
       
    if ((region.getRowFrom() >= pStartRow)
         
    && (region.getRowTo() <= pEndRow)) {
        targetRowFrom 
    = region.getRowFrom() - pStartRow + pPosition;
        targetRowTo 
    = region.getRowTo() - pStartRow + pPosition;
        region.setRowFrom(targetRowFrom);
        region.setRowTo(targetRowTo);
        targetSheet.addMergedRegion(region);
       }

      }

      
    // 設(shè)置列寬
      for (i = pStartRow; i <= pEndRow; i++{
       sourceRow 
    = sourceSheet.getRow(i);
       
    if (sourceRow != null{
        
    for (j = sourceRow.getLastCellNum(); j > sourceRow
          .getFirstCellNum(); j
    --{
         targetSheet
           .setColumnWidth(j, sourceSheet.getColumnWidth(j));
         targetSheet.setColumnHidden(j, 
    false);
        }

        
    break;
       }

      }

      
    // 拷貝行并填充數(shù)據(jù)
      for (; i <= pEndRow; i++{
       sourceRow 
    = sourceSheet.getRow(i);
       
    if (sourceRow == null{
        
    continue;
       }

       targetRow 
    = targetSheet.createRow(i - pStartRow + pPosition);
       targetRow.setHeight(sourceRow.getHeight());
       
    for (j = sourceRow.getFirstCellNum(); j < sourceRow
         .getPhysicalNumberOfCells(); j
    ++{
        sourceCell 
    = sourceRow.getCell(j);
        
    if (sourceCell == null{
         
    continue;
        }

        targetCell 
    = targetRow.createCell(j);
        targetCell.setEncoding(sourceCell.getEncoding());
        targetCell.setCellStyle(sourceCell.getCellStyle());
        cType 
    = sourceCell.getCellType();
        targetCell.setCellType(cType);
        
    switch (cType) {
        
    case HSSFCell.CELL_TYPE_BOOLEAN:
         targetCell.setCellValue(sourceCell.getBooleanCellValue());
         System.out.println(
    "--------TYPE_BOOLEAN:"
           
    + targetCell.getBooleanCellValue());
         
    break;
        
    case HSSFCell.CELL_TYPE_ERROR:
         targetCell
           .setCellErrorValue(sourceCell.getErrorCellValue());
         System.out.println(
    "--------TYPE_ERROR:"
           
    + targetCell.getErrorCellValue());
         
    break;
        
    case HSSFCell.CELL_TYPE_FORMULA:
         
    // parseFormula這個函數(shù)的用途在后面說明
         targetCell.setCellFormula(parseFormula(sourceCell
           .getCellFormula()));
         System.out.println(
    "--------TYPE_FORMULA:"
           
    + targetCell.getCellFormula());
         
    break;
        
    case HSSFCell.CELL_TYPE_NUMERIC:
         targetCell.setCellValue(sourceCell.getNumericCellValue());
         System.out.println(
    "--------TYPE_NUMERIC:"
           
    + targetCell.getNumericCellValue());
         
    break;
        
    case HSSFCell.CELL_TYPE_STRING:
         targetCell
           .setCellValue(sourceCell.getRichStringCellValue());
         System.out.println(
    "--------TYPE_STRING:" + i
           
    + targetCell.getRichStringCellValue());
         
    break;
        }


       }


      }


     }


     
    private static String parseFormula(String pPOIFormula) {
      
    final String cstReplaceString = "ATTR(semiVolatile)"//$NON-NLS-1$
      StringBuffer result = null;
      
    int index;

      result 
    = new StringBuffer();
      index 
    = pPOIFormula.indexOf(cstReplaceString);
      
    if (index >= 0{
       result.append(pPOIFormula.substring(
    0, index));
       result.append(pPOIFormula.substring(index
         
    + cstReplaceString.length()));
      }
     else {
       result.append(pPOIFormula);
      }


      
    return result.toString();
     }


    }


    posted on 2007-11-14 16:51 liaojiyong 閱讀(8319) 評論(1)  編輯  收藏 所屬分類: POI

    評論

    # re: POI 復(fù)制excel一行到另外一個sheet頁(轉(zhuǎn))[未登錄] 2011-12-26 16:02 zz

    請問pPosition參數(shù)是什么?  回復(fù)  更多評論   

    主站蜘蛛池模板: 国产一级淫片a免费播放口| 成人国产网站v片免费观看| 免费人成在线观看网站品爱网 | 亚洲aⅴ无码专区在线观看| 成人免费视频观看无遮挡| 亚洲精品免费网站| 免费视频淫片aa毛片| 亚洲AV无码成人精品区日韩| 日韩在线视频免费看| 国产亚洲精品2021自在线| 亚洲日韩中文在线精品第一| 高清免费久久午夜精品| 亚洲中文字幕久久精品无码喷水| 免费在线观影网站| 久久精品亚洲精品国产色婷| 国拍在线精品视频免费观看 | 18禁超污无遮挡无码免费网站国产 | 亚洲精品亚洲人成在线| 免费一级毛片在线观看| 国产精品偷伦视频免费观看了 | 无码一区二区三区免费| 亚洲无人区视频大全| 成年性羞羞视频免费观看无限| 久久亚洲AV成人无码国产最大| 又粗又黄又猛又爽大片免费| 两性色午夜视频免费网| 内射少妇36P亚洲区| 韩国免费三片在线视频| 国产精品免费看久久久香蕉| 久久亚洲熟女cc98cm| 男女啪啪永久免费观看网站| 韩国免费A级毛片久久| 亚洲日韩乱码中文无码蜜桃臀| 麻豆国产VA免费精品高清在线 | 97无码免费人妻超级碰碰碰碰| 精品特级一级毛片免费观看| 亚洲国产精品嫩草影院在线观看 | 国语成本人片免费av无码| 美女裸免费观看网站| 亚洲午夜精品久久久久久人妖| 最近免费中文字幕大全视频|