<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);
      // 創(chuàng)建工作文檔對(duì)象
      Workbook wb = null;
      if (fileType.equals("xls")) {
       wb = new HSSFWorkbook(stream);
      } else if (fileType.equals("xlsx")) {
       wb = new XSSFWorkbook(stream);
      } else {
       System.out.println("您的文檔格式不正確!");
      }
      // 創(chuàng)建sheet對(duì)象
      Sheet sheet1 = (Sheet) wb.getSheetAt(0);
      // 循環(huán)寫入行數(shù)據(jù)
       int num = sheet1.getLastRowNum() + 1;
      for (int i = 0; i < 5; i++) {
       Row row = (Row) sheet1.createRow(num+i);
       // 循環(huán)寫入列數(shù)據(jù)
       for (int j = 0; j < 8; j++) {
        Cell cell = row.createCell(j);
        cell.setCellValue("測(cè)試" + 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 閱讀(298) 評(píng)論(0)  編輯  收藏


    只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


    網(wǎng)站導(dǎo)航:
     
    <2013年8月>
    28293031123
    45678910
    11121314151617
    18192021222324
    25262728293031
    1234567

    導(dǎo)航

    統(tǒng)計(jì)

    常用鏈接

    留言簿(2)

    隨筆檔案

    文章檔案

    搜索

    最新評(píng)論

    閱讀排行榜

    評(píng)論排行榜

    主站蜘蛛池模板: 91免费国产精品| 中文字幕免费在线观看| 手机看片久久国产免费| 亚洲国产精品张柏芝在线观看| mm1313亚洲精品国产| 不卡精品国产_亚洲人成在线| 99人中文字幕亚洲区| 无码日韩精品一区二区三区免费 | 久久久久av无码免费网| 久久精品网站免费观看| 亚洲国产人成中文幕一级二级| 国产亚洲人成在线影院| 免费一级毛片一级毛片aa| 亚洲精品免费在线| 国产精品美女久久久免费 | 2020因为爱你带字幕免费观看全集| 成人性生交视频免费观看| 亚洲日韩一区二区一无码| 一级毛片免费观看不卡的| 亚洲综合在线成人一区| 在线免费观看一级毛片| 国产成人亚洲综合无| 亚洲综合AV在线在线播放| 91精品免费不卡在线观看| 91丁香亚洲综合社区| 99久久人妻精品免费一区| 亚洲国产综合在线| 国产精品色午夜免费视频| 成人久久免费网站| 亚洲一区二区三区免费在线观看| 在线免费观看视频你懂的| 国产无限免费观看黄网站| 噜噜噜亚洲色成人网站∨| 久久99精品视免费看| 久久精品国产亚洲av麻豆蜜芽 | 羞羞漫画在线成人漫画阅读免费| 亚洲另类激情专区小说图片| 久久精品一区二区免费看| 亚洲精品乱码久久久久久久久久久久| 亚洲免费在线视频| 亚洲精品无码成人片久久不卡 |