<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不適合商業(yè)應用,它都是會莫名其妙的讀不出來數(shù)據(jù)。
      2、Apache POI是一純Java的實現(xiàn),不僅能讀微軟的Excel還可以讀Open Office的,新版HSSF3.0還添加了讀取Power Point的功能。總之是一種非常穩(wěn)定,強大的實現(xiàn)。推薦使用。


    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結束,
              結束的數(shù)目不知什么原因與顯示的長度不同,可能會偏長
     
     如何插圖片到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 周銳 閱讀(470) 評論(0)  編輯  收藏 所屬分類: ApacheJava
    主站蜘蛛池模板: wwwxxx亚洲| 亚洲欧洲日本国产| 日韩精品福利片午夜免费观着| 国产成人高清精品免费观看| 国产亚洲国产bv网站在线| 国产亚洲精品va在线| 日本特黄特色免费大片| 亚州免费一级毛片| 国产亚洲精品免费视频播放| 精品免费AV一区二区三区| 亚洲免费观看在线视频| 久久亚洲国产成人亚| 亚洲人成人网站在线观看| 在线观看免费精品国产| 在线观看无码AV网站永久免费| 久久成人免费播放网站| 国产视频精品免费视频| 特级毛片免费观看视频| 小说区亚洲自拍另类| 国产成人精品久久亚洲高清不卡| 国产成人亚洲精品| 亚洲人成在线免费观看| 亚洲综合久久1区2区3区| 久久亚洲精品无码| 亚洲va久久久噜噜噜久久天堂| 国产成人精品久久亚洲| 亚洲精品国产精品国自产观看| 国产91在线免费| 四虎影视免费永久在线观看| 特级淫片国产免费高清视频| 热久久精品免费视频| 免费黄网在线观看| 日韩免费视频播播| 麻豆国产人免费人成免费视频| 在线a毛片免费视频观看| 在线不卡免费视频| avtt亚洲天堂| 成人午夜亚洲精品无码网站| 亚洲色爱图小说专区| 久久夜色精品国产嚕嚕亚洲av| 91大神亚洲影视在线|