专注于高品质PHP技术等信息服务于一体 [STIEMAP] [RSS]

百度提供的广告:
java
当前位置:首页 > 技术文档 > java >  > 
struts2-jxt导入电子表格并下载支持中文

    public String downXls()throws Exception{
        List<TbCourseMng> all=coursedao.findCourseAll();
        ServletActionContext.getResponse().setContentType("application/x-msdownload");
        ServletActionContext.getResponse().setHeader("Content-disposition","attachment; "+
                "filename="+new String("考试成绩模板.xls".getBytes("gb2312"),"iso8859-1"));
        WritableWorkbook workbook =Workbook.createWorkbook(ServletActionContext.getResponse().getOutputStream());
        WritableSheet sh=workbook.createSheet("课程表", 0);
        //字符串
        Label temp=new Label(0,0,"学生编号");
        sh.addCell(temp);
         temp=new Label(1,0,"学生姓名");
        sh.addCell(temp);
        int count=1;
        for (TbCourseMng tbCourseMng : all) {
             temp=new Label(++count,0,tbCourseMng.getCOURSE_NAME());
             sh.addCell(temp);
        }
        workbook.write();
        workbook.close();
        return null;
    }