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

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

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

    翱翔的Eagle

    —— 世界上沒有垃圾,只有放錯了地方的財寶!

    BlogJava 首頁 新隨筆 聯系 聚合 管理
      3 Posts :: 0 Stories :: 1 Comments :: 0 Trackbacks
    package ?org.eagle.jexcel;

    import ?jxl. * ;
    import ?jxl.format.UnderlineStyle;
    import ?jxl.write. * ;
    import ?jxl.write.Number;
    import ?jxl.write.Boolean;
    import ?java.io. * ;

    /**
    ?*?
    ?*?<p>
    ?*?Title:
    ?*?</p>
    ?*?
    ?*?<p>
    ?*?Description:
    ?*?</p>
    ?*?
    ?*?<p>
    ?*?Copyright:?Copyright?(c)?2006
    ?*?</p>
    ?*?
    ?*?<p>
    ?*?Company:
    ?*?</p>
    ?*?
    ?*?
    @author ?eagle
    ?*?
    @version ?1.0
    ?
    */
    public ? class ?JexcelHandle?{
    ????
    public ?JexcelHandle()?{
    ????}

    ????
    public ? static ? void ?writeExcel(OutputStream?os)?{
    ????????
    try ?{
    ????????????WritableWorkbook?wwb?
    = ?Workbook.createWorkbook(os);
    ????????????
    // ?創建excel工作表?鎮定名稱和位置
    ????????????WritableSheet?ws? = ?wwb.createSheet( " card?sheet? " ,? 0 );
    ????????????
    // ?1.添加Label對象
    ????????????Label?label? = ? new ?Label( 0 ,? 0 ,? " 編號 " );
    ????????????ws.addCell(label);
    ????????????Label?label2?
    = ? new ?Label( 1 ,? 0 ,? " 沖值卡號 " );
    ????????????ws.addCell(label2);
    ????????????Label?label3?
    = ? new ?Label( 2 ,? 0 ,? " 沖值卡密碼 " );
    ????????????ws.addCell(label3);
    ????????????Label?label4?
    = ? new ?Label( 3 ,? 0 ,? " 最晚沖值時間 " );
    ????????????ws.addCell(label4);
    ????????????Label?label5?
    = ? new ?Label( 4 ,? 0 ,? " 沖值的面值(TC)(1RMB=100TC) " );
    ????????????ws.addCell(label5);
    ????????????Label?label6?
    = ? new ?Label( 5 ,? 0 ,? " 是否作廢 " );
    ????????????ws.addCell(label6);

    ????????????Number?labelN?
    = ? new ?Number( 0 ,? 1 ,? 3.1415926 );
    ????????????ws.addCell(labelN);
    ????????????
    // 通過?記錄集的方式可以得到數據庫中的相關的記錄
    ????????????
    // ?WritableFont?wf?=?new?WritableFont(WritableFont.TIMES,?18,
    ????????????
    // ?WritableFont.BOLD,?true);
    ????????????
    // ?WritableCellFormat?wcf?=?new?WritableCellFormat(wf);
    ????????????
    // ?Label?labelcf?=?new?Label(1,?0,?"this?is?a?label?test",?wcf);
    ????????????
    // ?ws.addCell(labelcf);
    ????????????
    // ? // 2.添加Number對象
    ????????????
    // ?Number?labelN?=?new?Number(0,1,3.1415926);
    ????????????
    // ?ws.addCell(labelN);
    ????????????
    //
    ????????????
    // ? // 添加帶有formatting的Number對象
    ????????????
    // ?NumberFormat?nf?=?new?NumberFormat("#.##");
    ????????????
    // ?WritableCellFormat?wcfN?=?new?WritableCellFormat(nf);
    ????????????
    // ?Number?labelNF?=?new?jxl.write.Number(1,1,3.1415926,wcfN);
    ????????????
    // ?ws.addCell(labelNF);
    ????????????
    //
    ????????????
    // ? // 3.添加Boolean對象
    ????????????
    // ?Boolean?labelB?=?new?jxl.write.Boolean(0,2,false);
    ????????????
    // ?ws.addCell(labelB);
    ????????????
    //
    ????????????
    // ? // 4.添加DateTime對象
    ????????????
    // ?jxl.write.DateTime?labelDT?=?new?jxl.write.DateTime(0,3,new
    ????????????
    // ?java.util.Date());
    ????????????
    // ?ws.addCell(labelDT);
    ????????????
    //
    ????????????
    // ? // 添加帶有formatting的DateFormat對象
    ????????????
    // ?DateFormat?df?=?new?DateFormat("dd?MM?yyyy?hh:mm:ss");
    ????????????
    // ?WritableCellFormat?wcfDF?=?new?WritableCellFormat(df);
    ????????????
    // ?DateTime?labelDTF?=?new?DateTime(1,3,new?java.util.Date(),wcfDF);
    ????????????
    // ?ws.addCell(labelDTF);
    ????????????
    //
    ????????????
    // ? // 添加圖片對象,jxl只支持png格式圖片
    ????????????
    // ?File?image?=?new?File("f:\\x.png");
    ????????????
    // ?WritableImage?wimage?=?new
    ????????????
    // ?WritableImage(0,1,2,2,image); // 0,1分別代表x,y.2,2代表寬和高占的單元格數
    ????????????
    // ?ws.addImage(wimage);
    ????????????
    // ?寫入工作表
    ????????????wwb.write();
    ????????????wwb.close();
    ????????}?
    catch ?(Exception?e)?{
    ????????????System.out.println(
    "" ? + ?e);
    ????????}

    ????}



    ????
    public ? static ? void ?modifyExcel(File?file1,?File?file2)?{
    ????????
    try ?{
    ????????????
    // ?先copy?在操作第二個文件修改,
    ????????????Workbook?rwb? = ?Workbook.getWorkbook(file1);
    ????????????WritableWorkbook?wwb?
    = ?Workbook.createWorkbook(file2,?rwb); // ?copy
    ????????????WritableSheet?ws? = ?wwb.getSheet( 0 );
    ????????????WritableCell?wc?
    = ?ws.getWritableCell( 0 ,? 0 );

    ????????????
    // ?判斷單元格的類型,做出相應的轉換
    ????????????Label?label? = ?(Label)?wc;
    ????????????label.setString(
    " ?1 " );

    ????????????wwb.write();
    ????????????wwb.close();
    ????????????rwb.close();
    ????????}?
    catch ?(Exception?e)?{
    ????????????e.printStackTrace();
    ????????}
    ????}

    ????
    /**
    ?????*?讀取Excel
    ?????*?
    ?????*?
    @param ?filePath
    ?????
    */
    ????
    public ? static ? void ?readExcel(String?filePath)?{
    ????????
    try ?{
    ????????????InputStream?is?
    = ? new ?FileInputStream(filePath);
    ????????????Workbook?rwb?
    = ?Workbook.getWorkbook(is);
    ????????????
    // ?Sheet?st?=?rwb.getSheet("0")這里有兩種方法獲取sheet表,1為名字,而為下標,從0開始
    ????????????Sheet?st? = ?rwb.getSheet( " original " );
    ????????????Cell?c00?
    = ?st.getCell( 0 ,? 0 );
    ????????????
    // ?通用的獲取cell值的方式,返回字符串
    ????????????String?strc00? = ?c00.getContents();
    ????????????
    // ?獲得cell具體類型值的方式
    ???????????? if ?(c00.getType()? == ?CellType.LABEL)?{
    ????????????????LabelCell?labelc00?
    = ?(LabelCell)?c00;
    ????????????????strc00?
    = ?labelc00.getString();
    ????????????}
    ????????????
    // ?輸出
    ????????????System.out.println(strc00);
    ????????????
    // ?關閉
    ????????????rwb.close();
    ????????}?
    catch ?(Exception?e)?{
    ????????????e.printStackTrace();
    ????????}
    ????}

    ????
    public ? static ? void ?main(String?args[])?{
    ????????
    try ?{
    ????????????File?fileWrite?
    = ? new ?File( " f:/cardWrite.xls " );
    ????????????fileWrite.createNewFile();
    ????????????OutputStream?os?
    = ? new ?FileOutputStream(fileWrite);
    ????????????JexcelHandle.writeExcel(os);
    ????????????JexcelHandle.modifyExcel(
    new ?File( " f:/cardWrite.xls " ),? new ?File(
    ????????????????????
    " f:/cardWrite2.xls " ));
    ????????}?
    catch ?(Exception?e)?{
    ????????????System.out.println(e);
    ????????}
    ????}

    }
    在網上看了寫源碼在結合自己的。不要忘了下載jxl包喲。http://www.andykhan.com/jexcelapi/
    <%@?page?contentType="text/html;?charset=utf-8"?language="java"?import="java.sql.*"?errorPage=""?%>
    <%@?page?import="org.eagle.gz.*"%>
    <%@?page?import="java.io.*"%>
    <html>
    <head>
    <meta?http-equiv="Content-Type"?content="text/html;?charset=utf-8">
    <title>無標題文檔</title>
    <style?type="text/css">
    <!--
    body,td,th?{
    ????font
    -size:?12px;
    }
    body?{
    ????margin
    -left:?0px;
    ????margin
    -top:?0px;
    ????margin
    -right:?0px;
    ????margin
    -bottom:?0px;
    }
    -->
    </style></head>

    <body>

    <%
    try{
    response.reset();
    //清除Buffer
    response.setContentType("application/vnd.ms-excel");
    File?fileWrite?
    =?new?File("f:/testWrite.xls");
    fileWrite.createNewFile();
    new?FileOutputStream(fileWrite);
    JexcelHandle.writeExcel(
    new?FileOutputStream(fileWrite));
    }
    catch(Exception?e){
    ????System.out.println(e);
    }
    %>
    </body>
    </html>
    也可以在jsp中運用,
    群 16687185? 歡迎你們的加盟。
    posted on 2006-09-20 18:16 skyeagle 閱讀(2060) 評論(1)  編輯  收藏

    評論

    # re: java 生成excel文件 可以做為簡單的報表工具 2007-03-05 19:41 rewr
    rewrwer  回復  更多評論
      


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


    網站導航:
     
    主站蜘蛛池模板: 一区二区三区四区免费视频 | 亚洲色最新高清av网站| 99在线在线视频免费视频观看 | 国产日产亚洲系列| 本道天堂成在人线av无码免费 | 亚洲AV永久青草无码精品| 中文在线观看免费网站| 亚洲五月综合缴情在线观看| 永久免费AV无码网站国产| 精品久久香蕉国产线看观看亚洲| 久99久无码精品视频免费播放| 亚洲电影日韩精品| 好吊色永久免费视频大全| 亚洲高清国产AV拍精品青青草原| 男人进去女人爽免费视频国产| 亚洲AV日韩AV高潮无码专区| 96免费精品视频在线观看| 亚洲偷自精品三十六区| 香蕉高清免费永久在线视频| 最好2018中文免费视频| 国产亚洲av片在线观看播放| 91成人在线免费视频| 亚洲精品伊人久久久久| 国产精品国产午夜免费福利看| 人妻18毛片a级毛片免费看| 久久精品国产亚洲网站| 久久久久久曰本AV免费免费| 亚洲熟女综合色一区二区三区| 免费A级毛片无码A∨男男| 三级黄色在线免费观看| 亚洲人成电影网站| 免费一级毛片在播放视频| 国产色爽免费无码视频| 国产亚洲国产bv网站在线| jjzz亚洲亚洲女人| 最近中文字幕国语免费完整 | 亚洲午夜无码毛片av久久京东热| 亚洲国产av一区二区三区| 一级毛片免费观看不卡视频| 亚洲精品无码久久| 亚洲AV无码精品色午夜果冻不卡|