springmvc 导出excel
来源:互联网 发布:双11淘宝c店 编辑:程序博客网 时间:2024/05/21 09:16
- // 导出excel方法
- @RequestMapping("exportExcel")
- public void exportExcel(HttpServletRequest request, HttpServletResponse response)
- {
- HttpSession session = request.getSession();
- session.setAttribute("state", null);
- // 生成提示信息,
- response.setContentType("application/vnd.ms-excel");
- String codedFileName = null;
- OutputStream fOut = null;
- try
- {
- // 进行转码,使其支持中文文件名
- codedFileName = java.net.URLEncoder.encode("中文","UTF-8");
- response.setHeader("content-disposition","attachment;filename=" + codedFileName +".xls");
- // response.addHeader("Content-Disposition", "attachment; filename=" + codedFileName + ".xls");
- // 产生工作簿对象
- HSSFWorkbook workbook = new HSSFWorkbook();
- //产生工作表对象
- HSSFSheet sheet = workbook.createSheet();
- for (int i =0; i <= 30000; i++)
- {
- HSSFRow row = sheet.createRow((int)i);//创建一行
- HSSFCell cell = row.createCell((int)0);//创建一列
- cell.setCellType(HSSFCell.CELL_TYPE_STRING);
- cell.setCellValue("测试成功" + i);
- }
- fOut = response.getOutputStream();
- workbook.write(fOut);
- }
- catch (UnsupportedEncodingException e1)
- {}
- catch (Exception e)
- {}
- finally
- {
- try
- {
- fOut.flush();
- fOut.close();
- }
- catch (IOException e)
- {}
- session.setAttribute("state","open");
- }
- System.out.println("文件生成...");
- }
- @RequestMapping("check")
- public void check(HttpServletRequest request, HttpServletResponse response)
- {
- try
- {
- if ("open".equals(request.getSession().getAttribute("state")))
- {
- request.getSession().setAttribute("state",null);
- response.getWriter().write("true");
- response.getWriter().flush();
- }
- else
- {
- response.getWriter().write("false");
- response.getWriter().flush();
- }
- }
- catch (IOException e)
- {}
- }
- /***********导出start************/
- var excel_flag = 0;
- var win_check;
- var exportExcelBtn = new Ext.Button({
- renderTo:'exportExcelBtn',
- text:"<span class='marL10'>"+'导出'+"</span>",
- height:24,
- iconCls:'findnew',
- width:110,
- bodyStyle:'padding:5px',
- handler: function()
- {
- excel_flag = 0;
- //禁用按钮
- exportExcelBtn.disable();
- location.href = "exportExcel";
- //每隔一秒向后台发送请求
- win_check = window.setInterval(check, 1000);
- }
- });
- /**
- * 用于防止重复提交
- */
- function check()
- {
- excel_flag ++;
- if(excel_flag > 30)
- {
- //清空定时器
- window.clearInterval(win_check);
- //启用按钮
- exportExcelBtn.enable();
- }
- Ext.Ajax.request(
- {
- url : 'check',
- success : function (response, result)
- {
- if(response.responseText=="true")
- {
- //清空定时器
- window.clearInterval(win_check);
- //启用按钮
- exportExcelBtn.enable();
- }
- }
- })
- }
- /***********导出end*****************/
0 0
- springmvc导出excel
- springmvc导出excel
- SpringMVC POI导出EXCEL
- springmvc 导出excel
- SpringMVC导出Excel
- springmvc导出excel
- springMVC+poi导出excel
- jxl 导出excel springMVC
- Springmvc导出excel表
- jasperReport导出excel(springMvc)
- springMVC导出excel
- SpringMVC导出Excel
- springmvc 导出excel
- SpringMVC 导出Excel案例
- springMVC导出Excel(二)
- Springmvc 使用 AbstractExcelView 导出excel
- SpringMVC + poi 导出excel表格
- springMVC中导出excel案例
- iOS分辨率
- 如何让WebService的返回类型不是XML
- item属性总结
- Android工程文件下assets文件夹与res文件夹的区别
- 字节序整理
- springmvc 导出excel
- 顺序表----数组结构c++
- PDF在线转换成word免费版
- Altium Designer10 如何导出Gerber文件
- HDU2043 密码
- uva--1588
- VC++中使用ADO方式操作ACCESS数据库
- android环境配置 自配
- acpi package has zero elements错误的解决