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

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

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

    posts - 431,  comments - 344,  trackbacks - 0

    一,JExcelAPI與Apache POI兩者對比
      1、JExcelAPI不適合商業應用,它都是會莫名其妙的讀不出來數據。
      2、Apache POI是一純Java的實現,不僅能讀微軟的Excel還可以讀Open Office的,新版HSSF3.0還添加了讀取Power Point的功能。總之是一種非常穩定,強大的實現。推薦使用。


    Jexcelapi的使用參考:http://blog.csdn.net/yfhdsz/archive/2006/10/30/1356670.aspx

    apache POI 參考:http://blog.csdn.net/yuansicau/archive/2006/08/31/1150046.aspx
    關鍵是要理解
     java讀取excel文件的順序是:
    Excel文件->工作表->行->單元格 對應到POI中,為:workbook->sheet->row->cell
    注意:
     注意:  
              1.sheet, 以0開始,以workbook.getNumberOfSheets()-1結束
       2.row, 以0開始(getFirstRowNum),以getLastRowNum結束
       3.cell, 以0開始(getFirstCellNum),以getLastCellNum結束,
              結束的數目不知什么原因與顯示的長度不同,可能會偏長
     
     如何插圖片到Excel中
     public static void createPicture() {
      FileOutputStream fileOut = null;
      BufferedImage bufferImg = null;
      BufferedImage bufferImg1 = null;
      try {
       ByteArrayOutputStream byteArrayOut = new ByteArrayOutputStream();
       ByteArrayOutputStream byteArrayOut1 = new ByteArrayOutputStream();
       bufferImg = ImageIO.read(new File("C:/Documents and Settings/All Users/Documents/My Pictures/示例圖片/Sunset.jpg"));
       bufferImg1 = ImageIO.read(new File("C:/Documents and Settings/All Users/Documents/My Pictures/示例圖片/Water lilies.jpg"));
       ImageIO.write(bufferImg, "jpeg", byteArrayOut);
       ImageIO.write(bufferImg1, "jpeg", byteArrayOut1);

       HSSFWorkbook wb = new HSSFWorkbook();
       HSSFSheet sheet1 = wb.createSheet("new sheet");
       // HSSFRow row = sheet1.createRow(2);
       HSSFPatriarch patriarch = sheet1.createDrawingPatriarch();
       HSSFClientAnchor anchor = new HSSFClientAnchor(0, 0, 512, 255,
         (short) 0, 0, (short) 10, 10);
       HSSFClientAnchor anchor1 = new HSSFClientAnchor(0, 0, 512, 255,
         (short) 0, 15, (short) 10, 20);
       /**
        * public HSSFClientAnchor(int dx1, int dy1, int dx2, int dy2, short
        * col1, int row1, short col2, int row2)
        * Creates a new client anchor
        * and sets the top-left and bottom-right coordinates of the anchor.
        *
        * Parameters: dx1 - the x coordinate within the first cell.
        * dy1 - the y coordinate within the first cell.
        * dx2 - the x coordinate within the second cell.
        * dy2 - the y coordinate within the second cell.
        * col1 - the column (0 based) of the first cell.
        * row1 - the row (0 based) of the first cell.
        * col2 - the column (0 based) of the second cell.
        * row2 - the row (0 based) of the second cell.
        * 注意:(col1,row1)表示圖片左上角所在單元格
        * (col2,row2)表示圖片右下角所在單元格,
        * 先是列,再行,順序不要反了.
        * (dx1,dy1)表示圖片左上角在單元格中的坐標.
        * ((dx2,dy2)表示圖片右下角在單元格中的坐標.
        */
       patriarch.createPicture(anchor, wb.addPicture(byteArrayOut
         .toByteArray(), HSSFWorkbook.PICTURE_TYPE_JPEG));
       patriarch.createPicture(anchor1, wb.addPicture(byteArrayOut1
         .toByteArray(), HSSFWorkbook.PICTURE_TYPE_JPEG));

       fileOut = new FileOutputStream("e:/study/workbook.xls");
       wb.write(fileOut);
       fileOut.close();

      } catch (IOException io) {
       io.printStackTrace();
       System.out.println("io erorr :  " + io.getMessage());
      } finally {
       if (fileOut != null)
        try {
         fileOut.close();
        } catch (IOException e) {
         // TODO Auto-generated catch block
         e.printStackTrace();
        }
      }
     }

    posted on 2008-07-04 11:38 周銳 閱讀(469) 評論(0)  編輯  收藏 所屬分類: ApacheJava
    主站蜘蛛池模板: 中文字幕的电影免费网站| 五月亭亭免费高清在线| 凹凸精品视频分类国产品免费| 亚洲国产精品乱码在线观看97| 成年性生交大片免费看| 亚洲AV日韩精品久久久久久 | 久久亚洲欧洲国产综合| 国产亚洲精彩视频| 亚洲国产成人五月综合网| 亚洲精品无码高潮喷水在线| 人妖系列免费网站观看| 综合久久久久久中文字幕亚洲国产国产综合一区首 | 全免费a级毛片免费**视频| 亚洲国产成人九九综合| 国产精品免费在线播放| 一二三四影视在线看片免费| 亚洲国产日韩精品| 免费国产成人α片| 亚洲欧洲国产综合| 免费看韩国黄a片在线观看| 亚洲国产a∨无码中文777| 精品亚洲视频在线| 影音先锋在线免费观看| 亚洲精品美女久久久久| 国产精品免费观看久久| 特黄aa级毛片免费视频播放| 亚洲人成精品久久久久| 高清免费久久午夜精品| 亚洲AV无码成人网站久久精品大 | 成人免费无码大片a毛片软件| 相泽亚洲一区中文字幕| 日韩免费在线视频| 亚洲中文字幕无码久久综合网| 亚洲午夜理论片在线观看| 免费无遮挡无码永久在线观看视频 | 免费看黄的成人APP| www国产亚洲精品久久久| 亚洲欧美成人av在线观看| 国产成人亚洲精品影院| 成年网站免费入口在线观看| 亚洲一区二区三区电影|