servlet导出excel


	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		resp.setContentType("application/vnd.ms-excel;charset=gb2312");
//		resp.addHeader("Content-Disposition", "attachment;filename=kkkk.xls");
		HSSFWorkbook demoWorkBook = new HSSFWorkbook();
		HSSFSheet sheet =  demoWorkBook.createSheet("账号详单");
		HSSFRow row = sheet.createRow(0);
		HSSFCell cell = row.createCell(0);
		cell.setCellValue(11);
		ServletOutputStream out = resp.getOutputStream();
		demoWorkBook.write(out);
		out.flush();
		out.close();
	}



注视掉的也可以用,只是一个可以设置导出文件的名字,一个默认为test

你可能感兴趣的:(servlet,Excel)