隨筆-86  評(píng)論-767  文章-3  trackbacks-3

          首先,請(qǐng)到http://www.andykhan.com/jexcelapi/index.html下載java excel api,主頁上同時(shí)有比較詳細(xì)的介紹。最新版本為2.4.3,同時(shí)也可以到:http://www.andykhan.com/jexcelapi/jexcelapi_2_4_3.tar.gz下載到該最新版的API,由于該項(xiàng)目是開源的,所以下載的文件中已經(jīng)包含了源代碼,同樣的,文件中也有javadoc,大家在開發(fā)中可以參考javadoc。

          下載完畢后,我們需要把文件中的jxl.jar加入到你的開發(fā)classpath中。
          下圖是現(xiàn)在要生產(chǎn)的excel截圖:
          http://blog.csdn.net/beming/gallery/image/3437.aspx

          代碼如下:

          ???File excel = new File("d:/aming.xls");
          ???if(!excel.exists()){
          ????excel.createNewFile();
          ???}???
          ???WritableWorkbook wwb = Workbook.createWorkbook(excel);
          ???WritableSheet ws = wwb.createSheet("testexcel",0);
          ???Label lable = null;
          ???
          ???//對(duì)中文的支持非常好
          ???lable = new Label(0,0,"我的中國(guó)心");
          ???ws.addCell(lable);
          ???
          ???//可以定義模板格式化你的cell
          ???WritableFont wf = new WritableFont(WritableFont.ARIAL,10,WritableFont.NO_BOLD,false,UnderlineStyle.NO_UNDERLINE, Colour.BLACK);
          ???WritableCellFormat wcf = new WritableCellFormat(wf);
          ???wcf.setBackground(Colour.WHITE);
          ???lable = new Label(0,1,"fdsl",wcf);
          ???ws.addCell(lable);
          ???
          ???wf = new WritableFont(WritableFont.TIMES,18,WritableFont.BOLD,true);
          ???wcf = new WritableCellFormat(wf);
          ???lable = new Label(0,2,"aming",wcf);
          ???ws.addCell(lable);
          ???
          ???//cell的類型同樣可以定義為數(shù)字類型
          ???Number nb = new Number(0,3,21.4321321);
          ???ws.addCell(nb);
          ???
          ???//支持格式化你的數(shù)字串
          ???NumberFormat nf = new NumberFormat("#.###");
          ???wcf = new WritableCellFormat(nf);
          ???nb = new Number(0,4,21.43254354354354,wcf);
          ???ws.addCell(nb);

          ???//cell的類型可以為boolean類型
          ???Boolean bl = new Boolean(0,5,true);
          ???ws.addCell(bl);

          ???//cell的類型同樣可以為日期,時(shí)間
          ???DateTime dt = new DateTime(0,6,new Date());
          ???ws.addCell(dt);

          ???//并且可以很好格式化你的日期格式
          ???DateFormat df = new DateFormat("MM dd yyyy hh:mm:ss");
          ???wcf = new WritableCellFormat(df);
          ???dt = new DateTime(0,7,new Date(),wcf);
          ???ws.addCell(dt);
          ???
          ???//開始寫文件了
          ???wwb.write();
          ???wwb.close();

          上面的下載地址無法打開.
          下載請(qǐng)到:http://prdownloads.sourceforge.net/jexcelapi

          posted on 2005-01-14 14:57 eamoi 閱讀(3420) 評(píng)論(0)  編輯  收藏 所屬分類: Java
          主站蜘蛛池模板: 宁南县| 当涂县| 炎陵县| 商水县| 沙洋县| 长葛市| 阜新| 奎屯市| 洱源县| 南皮县| 南宁市| 甘德县| 永安市| 罗平县| 嘉兴市| 汉源县| 民乐县| 灵石县| 广宗县| 封丘县| 濮阳县| 枞阳县| 安福县| 增城市| 禹城市| 宁德市| 黄平县| 金堂县| 罗田县| 闽侯县| 海盐县| 白水县| 云南省| 民县| 苍南县| 田阳县| 江都市| 武威市| 长丰县| 高台县| 肃宁县|