white knight

导航

 

参考http://blog.163.com/lover_j_j/blog/static/1682474472006752454547/ 感谢原作者

 

public void service(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException
    {
        HSSFWorkbook wb = new HSSFWorkbook();
        HSSFSheet sheet = wb.createSheet();
        
        HSSFRow row1 = sheet.createRow((short) 0);
        HSSFCell a1 = row1.createCell((short) 0);
        a1.setCellValue("中文");
        
        res.setHeader("Content-Disposition", "attachment;filename=" + new String("测试文件.xls".getBytes("gbk"), "iso-8859-1"));
        res.setContentType("application/octet-stream");
        OutputStream out = res.getOutputStream();
        
        wb.write(out);
        
        out.close();
    }

posted on 2014-03-06 10:12  white knight  阅读(117)  评论(0)    收藏  举报