spring MVC 导出excel
来源:互联网 发布:微信默认浏览器是淘宝 编辑:程序博客网 时间:2024/05/22 03:31
- // 导出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)
- {}
- }
- // 导出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
- spring mvc 导出excel
- spring MVC 导出excel
- spring MVC 导出excel
- spring MVC 导出excel
- spring MVC 导出excel
- spring MVC 导出excel
- spring MVC 导出excel
- spring mvc 导出Excel
- Spring MVC 导出EXCEL
- Spring mvc 下Excel导出
- Spring mvc进行Excel导出
- Spring mvc 下导出Excel文件
- Jxls+Spring MVC实现Excel导出
- Jett+Spring MVC实现Excel导出
- spring mvc 条件查询导出excel
- spring mvc 导出Excel乱码问题解决办法。
- Jxls+Spring MVC实现Excel导出
- Spring MVC之excel表格导出
- JAVA调用RabbitMQ,附安装过程
- Unity AssetBundle的使用
- android https post
- 模版方法模式
- 【iOS开发-9】UIImage和UIImageView属性介绍,实现图片动画,实现开始/停止按钮效果
- spring MVC 导出excel
- ANTLR4权威指南 - 第7章 通过特定应用程序代码解耦语法
- 用户空间栈 & 系统空间栈
- _HEAP_LOOKASIDE
- UiObejct.getFromParent()
- 抽象工厂模式
- 返回时软键盘隐藏时候出现黑影
- sql查询语句优化
- 工厂模式--我的理解