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

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

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

    e代劍客——溫柔一刀

    生活就像海洋,只有意志堅(jiān)強(qiáng)的人,才能到達(dá)彼岸

       :: 首頁(yè) :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理 ::
      76 隨筆 :: 7 文章 :: 215 評(píng)論 :: 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()+"”的選課學(xué)生列表";?//?標(biāo)題
    ????????WritableSheet?wsheet?=?wbook.createSheet("第一頁(yè)",?0);?//?sheet名稱(chēng)
    ????????
    //?設(shè)置excel標(biāo)題
    ????????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);
    ????????
    //?開(kāi)始生成主體內(nèi)容????????????????
    ????????wsheet.addCell(new?Label(0,?2,?"課程名稱(chēng)"));
    ????????wsheet.addCell(
    new?Label(1,?2,?"學(xué)?號(hào)"));
    ????????wsheet.addCell(
    new?Label(2,?2,?"姓?名"));
    ????????wsheet.addCell(
    new?Label(3,?2,?"性?別"));
    ????????wsheet.addCell(
    new?Label(4,?2,?"學(xué)?院"));
    ????????wsheet.addCell(
    new?Label(5,?2,?"班?級(jí)"));
    ????????wsheet.addCell(
    new?Label(6,?2,?"專(zhuān)?業(yè)"));
    ????????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()));
    ????????}
    ????????
    ????????
    //?主體內(nèi)容生成結(jié)束????????
    ????????wbook.write();?//?寫(xiě)入文件
    ????????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");//?設(shè)定輸出文件頭
    ????????????response.setContentType("application/msexcel");//?定義輸出類(lèi)型
    ????????????ExcelBean?excelBean?=?new?ExcelBean();
    ????????????excelBean.expordExcel(os,courseList,studentList);
    //?調(diào)用生成excel文件bean
    ????????}
    ?catch?(Exception?e)?{
    ????????????System.out.println(e);
    ????????}
    ????????????
    ????????
    return?null;????
    ????}

    }

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

    評(píng)論

    # re: sping 、jxl 生成excel文件下載 2006-10-27 15:27 junitfans
    thanks   回復(fù)  更多評(píng)論
      

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

    # re: sping 、jxl 生成excel文件下載 2008-03-16 16:14 楊曉滿
    網(wǎng)上發(fā)了那么多下載Excel文件的例子,只有樓主這個(gè)看的最明白了,謝謝樓主啊.有機(jī)會(huì)向你多多請(qǐng)教.  回復(fù)  更多評(píng)論
      

    # re: sping 、jxl 生成excel文件下載 2009-10-19 14:35 javas
    對(duì)我很有幫助! 謝謝  回復(fù)  更多評(píng)論
      

    聯(lián)系偶 zhupanjava@gmail.com 溫柔一刀
    主站蜘蛛池模板: 亚洲人成在线免费观看| 国产精一品亚洲二区在线播放| 国产又黄又爽又猛的免费视频播放| 亚洲人成中文字幕在线观看| 欧洲美女大片免费播放器视频| 国产精品一区二区三区免费 | 久久91亚洲人成电影网站| 香港a毛片免费观看 | 亚洲视频免费在线看| 亚洲伊人久久成综合人影院| 亚洲日韩av无码| 亚洲va在线va天堂va888www| 亚洲高清资源在线观看| 激情综合亚洲色婷婷五月| 亚洲av片不卡无码久久| 免费大黄网站在线观| 亚洲精品成a人在线观看☆| 美女黄频免费网站| 日韩一级视频免费观看| 亚洲综合国产精品第一页| 亚洲AV成人片色在线观看| 精品无码无人网站免费视频| 亚洲AV日韩AV永久无码下载| 亚洲男女一区二区三区| 久久精品国产亚洲精品| 亚洲va在线va天堂va四虎| 91香蕉视频免费| 亚洲精品宾馆在线精品酒店| yy6080久久亚洲精品| 国产天堂亚洲精品| 亚洲成a人片在线不卡一二三区| 一边摸一边桶一边脱免费视频| 国产亚洲精品a在线观看| 国产精品免费_区二区三区观看| 91免费人成网站在线观看18| 中文字幕无码毛片免费看| 亚洲精品无码精品mV在线观看| 日本免费高清视频| 久久久久亚洲AV无码永不| av无码久久久久不卡免费网站| 亚洲福利视频一区二区|