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

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

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

    e代劍客——溫柔一刀

    生活就像海洋,只有意志堅強的人,才能到達彼岸

       :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理 ::
      76 隨筆 :: 7 文章 :: 215 評論 :: 0 Trackbacks
    ExcelBean.java文件用于生成Excel

    package?com.zhupan.util;

    import?java.io.OutputStream;
    import?java.util.List;

    import?jxl.Workbook;
    import?jxl.format.Colour;
    import?jxl.format.UnderlineStyle;
    import?jxl.write.Label;
    import?jxl.write.WritableCellFormat;
    import?jxl.write.WritableFont;
    import?jxl.write.WritableSheet;
    import?jxl.write.WritableWorkbook;

    import?com.ctgusec.model.Course_info;
    import?com.ctgusec.model.Student_info;

    public?class?ExcelBean?{

    ????
    public?String?expordExcel(OutputStream?os,?List?courseList,List?studentList)
    ????????????
    throws?Exception?{

    ????????WritableWorkbook?wbook?
    =?Workbook.createWorkbook(os);?//?建立excel文件
    ????????String?tmptitle?=?"課程“"+((Course_info)courseList.get(0)).getCource_name()+"”的選課學生列表";?//?標題
    ????????WritableSheet?wsheet?=?wbook.createSheet("第一頁",?0);?//?sheet名稱
    ????????
    //?設置excel標題
    ????????WritableFont?wfont?=?new?WritableFont(WritableFont.ARIAL,?16,
    ????????????????WritableFont.BOLD,?
    false,?UnderlineStyle.NO_UNDERLINE,
    ????????????????Colour.BLACK);
    ????????WritableCellFormat?wcfFC?
    =?new?WritableCellFormat(wfont);
    ????????wsheet.addCell(
    new?Label(1,?0,?tmptitle,?wcfFC));
    ????????wfont?
    =?new?jxl.write.WritableFont(WritableFont.ARIAL,?14,
    ????????????????WritableFont.BOLD,?
    false,?UnderlineStyle.NO_UNDERLINE,
    ????????????????Colour.BLACK);
    ????????wcfFC?
    =?new?WritableCellFormat(wfont);
    ????????
    //?開始生成主體內容????????????????
    ????????wsheet.addCell(new?Label(0,?2,?"課程名稱"));
    ????????wsheet.addCell(
    new?Label(1,?2,?"學?號"));
    ????????wsheet.addCell(
    new?Label(2,?2,?"姓?名"));
    ????????wsheet.addCell(
    new?Label(3,?2,?"性?別"));
    ????????wsheet.addCell(
    new?Label(4,?2,?"學?院"));
    ????????wsheet.addCell(
    new?Label(5,?2,?"班?級"));
    ????????wsheet.addCell(
    new?Label(6,?2,?"專?業"));
    ????????wsheet.addCell(
    new?Label(7,?2,?"備?注"));
    ????????
    for(int?i=3;i<studentList.size()+3;i++)
    ????????
    {
    ????????????wsheet.addCell(
    new?Label(0,?i,?((Course_info)courseList.get(0)).getCource_name()));
    ????????????wsheet.addCell(
    new?Label(1,?i,?((Student_info)studentList.get(0)).getStudentID()));
    ????????????wsheet.addCell(
    new?Label(2,?i,?((Student_info)studentList.get(0)).getName()));
    ????????????wsheet.addCell(
    new?Label(3,?i,?((Student_info)studentList.get(0)).getSex()));
    ????????????wsheet.addCell(
    new?Label(4,?i,?((Student_info)studentList.get(0)).getUnit()));
    ????????????wsheet.addCell(
    new?Label(5,?i,?((Student_info)studentList.get(0)).getClass_()));
    ????????????wsheet.addCell(
    new?Label(6,?i,?((Student_info)studentList.get(0)).getSpecialty()));
    ????????????wsheet.addCell(
    new?Label(7,?i,?((Student_info)studentList.get(0)).getRemark()));
    ????????}
    ????????
    ????????
    //?主體內容生成結束????????
    ????????wbook.write();?//?寫入文件
    ????????wbook.close();
    ????????os.close();
    ????????
    return?"success";
    ????}

    }


    控制器:

    package?com.ctgusec.spring;

    import?java.io.OutputStream;
    import?java.util.List;

    import?javax.servlet.http.HttpServletRequest;
    import?javax.servlet.http.HttpServletResponse;

    import?org.springframework.web.servlet.ModelAndView;
    import?org.springframework.web.servlet.mvc.AbstractController;

    import?com.ctgusec.service.ICourse_infoManage;
    import?com.zhupan.util.ExcelBean;

    public?class?EExcelDownController?extends?AbstractController?{
    ????
    ????
    private?ICourse_infoManage?courseManage;

    ????
    public?void?setCourseManage(ICourse_infoManage?courseManage)?{
    ????????
    this.courseManage?=?courseManage;
    ????}


    ????@Override
    ????
    protected?ModelAndView?handleRequestInternal(HttpServletRequest?request,
    ????????????HttpServletResponse?response)?
    throws?Exception?{????
    ????????Integer?course_id
    =new?Integer(request.getParameter("course_id"));
    ????????List?courseList
    =this.courseManage.getCourseById(course_id);????????
    ????????List?studentList?
    =?this.courseManage.getStudentByCourseId(course_id);
    ?????????
    try?{????
    ????????????OutputStream?os?
    =?response.getOutputStream();//?取得輸出流
    ????????????response.reset();//?清空輸出流
    ????????????response.setHeader("Content-disposition",?"attachment;?filename=student.xls");//?設定輸出文件頭
    ????????????response.setContentType("application/msexcel");//?定義輸出類型
    ????????????ExcelBean?excelBean?=?new?ExcelBean();
    ????????????excelBean.expordExcel(os,courseList,studentList);
    //?調用生成excel文件bean
    ????????}
    ?catch?(Exception?e)?{
    ????????????System.out.println(e);
    ????????}
    ????????????
    ????????
    return?null;????
    ????}

    }

    posted on 2006-10-08 18:12 溫柔一刀 閱讀(1988) 評論(4)  編輯  收藏 所屬分類: 開源框架

    評論

    # re: sping 、jxl 生成excel文件下載 2006-10-27 15:27 junitfans
    thanks   回復  更多評論
      

    # re: sping 、jxl 生成excel文件下載 2006-10-27 15:28 junitfans
    非常感謝,正需要  回復  更多評論
      

    # re: sping 、jxl 生成excel文件下載 2008-03-16 16:14 楊曉滿
    網上發了那么多下載Excel文件的例子,只有樓主這個看的最明白了,謝謝樓主啊.有機會向你多多請教.  回復  更多評論
      

    # re: sping 、jxl 生成excel文件下載 2009-10-19 14:35 javas
    對我很有幫助! 謝謝  回復  更多評論
      

    聯系偶 zhupanjava@gmail.com 溫柔一刀
    主站蜘蛛池模板: 日本XXX黄区免费看| 亚洲综合色婷婷七月丁香| 无码天堂va亚洲va在线va| 亚洲av无码乱码在线观看野外| 亚洲国产免费综合| 亚洲欧洲自拍拍偷综合| 性做久久久久免费观看| a毛片免费播放全部完整| 激情内射亚洲一区二区三区爱妻| 亚洲欧洲一区二区三区| 四虎在线成人免费网站| 日韩在线视频线视频免费网站| 久久亚洲精精品中文字幕| 国产免费变态视频网址网站 | 亚洲高清视频在线| 精品亚洲视频在线观看| 久久精品网站免费观看 | 美女被免费喷白浆视频| 人禽伦免费交视频播放| 亚洲精品天堂在线观看| 亚洲欧洲成人精品香蕉网| 成年美女黄网站18禁免费| 成人网站免费看黄A站视频| 亚洲1区2区3区精华液| 久久亚洲国产精品成人AV秋霞| 亚洲国产成人精品女人久久久 | 蜜臀亚洲AV无码精品国产午夜.| 亚洲三级电影网址| 亚洲美日韩Av中文字幕无码久久久妻妇| **一级毛片免费完整视| 中文字幕不卡免费高清视频| 亚洲av日韩av永久无码电影 | 十八禁的黄污污免费网站| 亚洲一级毛片免观看| 亚洲国产综合91精品麻豆| 亚洲免费日韩无码系列| 色www永久免费视频| 免费无码AV电影在线观看| 久久免费视频精品| 三年片在线观看免费西瓜视频| 一区二区三区精品高清视频免费在线播放|