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

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

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

    POI讀寫EXcel

    package com.wo116114.action;

    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.io.InputStream;

    import org.apache.poi.hssf.usermodel.HSSFWorkbook;
    import org.apache.poi.ss.usermodel.Cell;
    import org.apache.poi.ss.usermodel.Row;
    import org.apache.poi.ss.usermodel.Sheet;
    import org.apache.poi.ss.usermodel.Workbook;
    import org.apache.poi.xssf.usermodel.XSSFWorkbook;

    public class TestReadAndWrite {
     public static void main(String[] args) throws IOException {
      String path = "D:/dianping/gather/";
      String fileName = "result";
      String fileType = "xlsx";
       writer(path, fileName, fileType);
      
      read(path, fileName, fileType);
     }

     private static void writer(String path, String fileName, String fileType)
       throws IOException {
      InputStream stream = new FileInputStream(path + fileName + "."
        + fileType);
      // 創建工作文檔對象
      Workbook wb = null;
      if (fileType.equals("xls")) {
       wb = new HSSFWorkbook(stream);
      } else if (fileType.equals("xlsx")) {
       wb = new XSSFWorkbook(stream);
      } else {
       System.out.println("您的文檔格式不正確!");
      }
      // 創建sheet對象
      Sheet sheet1 = (Sheet) wb.getSheetAt(0);
      // 循環寫入行數據
       int num = sheet1.getLastRowNum() + 1;
      for (int i = 0; i < 5; i++) {
       Row row = (Row) sheet1.createRow(num+i);
       // 循環寫入列數據
       for (int j = 0; j < 8; j++) {
        Cell cell = row.createCell(j);
        cell.setCellValue("測試" + j);
       }
      }
      File file = new File(path + fileName + "." + fileType);
      FileOutputStream fileOut = new FileOutputStream(file);
      wb.write(fileOut);
      fileOut.close();
      stream.close();
     }

     public static void read(String path, String fileName, String fileType)
       throws IOException {
      InputStream stream = new FileInputStream(path + fileName + "."
        + fileType);
      Workbook wb = null;
      if (fileType.equals("xls")) {
       wb = new HSSFWorkbook(stream);
      } else if (fileType.equals("xlsx")) {
       wb = new XSSFWorkbook(stream);
      } else {
       System.out.println("您輸入的excel格式不正確");
      }
      Sheet sheet1 = wb.getSheetAt(0);
      for (Row row : sheet1) {
       for (Cell cell : row) {
        System.out.print(cell.getStringCellValue() + "  ");
       }
       System.out.println();
      }
     }
    }

    posted on 2013-08-22 14:02 Mr.lu 閱讀(304) 評論(0)  編輯  收藏


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


    網站導航:
     
    <2013年8月>
    28293031123
    45678910
    11121314151617
    18192021222324
    25262728293031
    1234567

    導航

    統計

    常用鏈接

    留言簿(2)

    隨筆檔案

    文章檔案

    搜索

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 亚洲另类自拍丝袜第1页| 亚洲国产综合无码一区| 亚洲国产午夜精品理论片| 女人体1963午夜免费视频| 久久夜色精品国产嚕嚕亚洲av| 亚洲情XO亚洲色XO无码| 亚洲狠狠ady亚洲精品大秀| 香蕉97碰碰视频免费| 日韩一品在线播放视频一品免费| 国产亚洲精品VA片在线播放| 成年性午夜免费视频网站不卡| 久久亚洲国产成人影院| 女人18毛片水真多免费看| 亚洲色婷婷六月亚洲婷婷6月| 国产免费区在线观看十分钟| 亚洲精品无码国产| 日本免费中文字幕| 亚洲六月丁香六月婷婷蜜芽| 在线观看成人免费视频| 国产精品亚洲专区在线播放| 三年片在线观看免费大全电影 | 永久黄网站色视频免费直播| 中文字幕亚洲综合久久男男| 国产午夜精品理论片免费观看| a毛片基地免费全部视频| 亚洲国产婷婷六月丁香| 99视频精品全部免费观看| 精品日韩99亚洲的在线发布| 鲁丝片一区二区三区免费| 伊在人亚洲香蕉精品区麻豆| 亚洲国产成人精品久久 | 亚洲伊人久久综合中文成人网| 免费日本一区二区| 亚洲人成人77777在线播放| 国产禁女女网站免费看| 日本高清不卡aⅴ免费网站| 亚洲AV无码乱码在线观看性色扶| 中文有码亚洲制服av片| 精品国产日韩亚洲一区| 久热中文字幕在线精品免费| 青草青草视频2免费观看|