java提交浏览器下载excel
public void excel(HttpServletResponse response) throws IOException {
HSSFWorkbook workbook = new HSSFWorkbook();
HSSFSheet sheet = workbook.createSheet("法人");
HSSFRow row=null;
for(int i=0;i<5;i++){
row = sheet.createRow(i);
row.createCell(0).setCellValue("序号");
row.createCell(1).setCellValue("账号");
row.createCell(2).setCellValue("");
row.createCell(3).setCellValue("起期");
row.createCell(4).setCellValue("止期");
row.createCell(5).setCellValue("");
row.createCell(6).setCellValue("部门");
}
OutputStream outStream = response.getOutputStream();
response.reset();
response.setContentType("application/vnd.ms-excel;charset=GBK");
response.setHeader("Content-Disposition",
new String("attachment;filename=工作簿.xls".getBytes("GBK"),
"ISO8859-1"));
try {
workbook.write(outStream);
} catch (Exception e) {
e.printStackTrace();
} finally {
outStream.close();
}
}