fileName = new String(fileName.getBytes("GBK"),"iso8859-1"); //转码
response.setContentType("application/vnd.ms-excel");
//response.setContentType( "APPLICATION/OCTET-STREAM" );
response.addHeader("Content-Disposition", "attachment; filename="+fileName+".xls");
workbook.write(response.getOutputStream());response.getOutputStream().flush();
response.getOutputStream().close();
这2行放到最后试看看。
response.setContentType("application/vnd.ms-excel");
//response.setContentType( "APPLICATION/OCTET-STREAM" );
response.addHeader("Content-Disposition", "attachment; filename="+fileName+".xls");
workbook.write(response.getOutputStream());response.getOutputStream().flush();
response.getOutputStream().close();
这2行放到最后试看看。
不过我用楼主的代码测试也没抛出java.lang.IllegalStateException异常,只是在打开excel文件时报“不能打开文档”fileName = new String(fileName.getBytes("GBK"),"iso8859-1"); //转码response.setContentType("application/vnd.ms-excel");
//response.setContentType( "APPLICATION/OCTET-STREAM" );
response.addHeader("Content-Disposition", "attachment; filename="+fileName+".xls");
response.getOutputStream().flush();
response.getOutputStream().close();workbook.write(response.getOutputStream());