spring+strust2+mybatis框架下的导出功能的实现
来源:互联网 发布:手机淘宝浏览单软件 编辑:程序博客网 时间:2024/06/05 02:46
1.html中:<button style="float: right" type="button" id="btnDownload" class="btn btn-primary">导出</button>2.js中://下载按钮绑定事件$("#btnDownload").bind("click", function() { var iframe = document.createElement("iframe"); iframe.src = "/CaiYiJia/detailPaymentOP_excelDataExport.do?"; iframe.style.display = "none"; document.body.appendChild(iframe);});3.Action:/** * excel导出加计扣除 * * @return * @throws */ public String excelDataExport() { log.info("方法excelDataExport开始"); selectPagingAddDeduction(); // 输入流定义 InputStream in = null; try { // 获取对象一览的流定义 in = this.getClass().getResourceAsStream( "/template/additional_deduction_list.xls"); // 读入模版到工作簿中 HSSFWorkbook work = new HSSFWorkbook(in); // 表格定义 HSSFSheet sheet = null; // 克隆sheet sheet = work.cloneSheet(0); // 设置该sheet的sheetName work.setSheetName(1, "加计扣除表"); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); // 判断是否含有数据 for (int i = 1; i < aaData.size() + 1; i++) { // 如果行数>8行 if (i >= 2) { // 从备份的表格中复制一行空行给当前表格 copyRow(sheet, work.getSheetAt(0), i, 1); } if (aaData.get(i - 1).getOrgVouDate() != null) { sheet.getRow(i).getCell(0).setCellValue(sdf.format(aaData.get(i - 1).getOrgVouDate())); } sheet.getRow(i).getCell(1).setCellValue(aaData.get(i - 1).getOrgVouNo()); sheet.getRow(i).getCell(2).setCellValue(aaData.get(i - 1).getOrgVouSubject()); sheet.getRow(i).getCell(3).setCellValue(aaData.get(i - 1).getOrgVouAmount().toString()); if (aaData.get(i - 1).getWeightedDeductionFlag() == 1) { sheet.getRow(i).getCell(4).setCellValue("是"); } if (aaData.get(i - 1).getWeightedDeductionFlag() == 0) { sheet.getRow(i).getCell(4).setCellValue("否"); } } // 删除第一个表格 work.removeSheetAt(0); // 获取页面的响应信息 HttpServletResponse response = ServletActionContext.getResponse(); // 取得输出流 OutputStream os = response.getOutputStream(); response.setContentType("application/vnd.ms-excel"); response.setHeader("Content-disposition","attachment;filename="+ java.net.URLEncoder.encode("additional_deduction_list", "UTF-8")+ ".xls"); work.write(os); os.close(); work.close(); in.close(); return null; } catch (FileNotFoundException ex) { ex.printStackTrace(); } catch (IOException ex) { ex.printStackTrace(); } log.info("方法excelDataExport结束"); return SUCCESS; } /* * 复制sheet的指定行到操作表格的指定行 * * @param sheet * * @param copySheet * * @param rowNum * * @param copyRowNum */ private void copyRow(HSSFSheet sheet, HSSFSheet copySheet, int rowNum, int copyRowNum) { HSSFRow copyRow = copySheet.getRow(copyRowNum); HSSFRow row = sheet.createRow(rowNum); Iterator<Cell> iter = copyRow.cellIterator(); while (iter.hasNext()) { HSSFCell copyCell = (HSSFCell) iter.next(); int index = copyCell.getColumnIndex(); HSSFCell cell = row.createCell(index); cell.setCellStyle(copyCell.getCellStyle()); cell.setCellType(copyCell.getCellType()); cell.setCellValue(copyCell.getStringCellValue()); } }4.项目中建一个文件夹放Excel模板
0 0
- spring+strust2+mybatis框架下的导出功能的实现
- web应用框架搭建。Strust2+Spring+Mybatis
- Spring框架下的管理员登录功能实现
- Spring框架下的管理员修改密码功能实现
- Mybatis框架实现功能的流程
- 菜鸟学SSM框架搭建----Spring+SpringMVC+MyBatis整合,实现简单的登录功能
- strust2框架的基本搭建
- spring+spring-mvc+mybatis框架权限的实现
- maven+spring+springmvc+mybatis+ajax 框架下实现简单的聊天室
- maven+spring+springmvc+mybatis+ajax 框架下实现简单的聊天室
- maven+spring+springmvc+mybatis+ajax 框架下实现简单的聊天室
- Spring、SpringMVC、MyBatis、freeMaker框架下之Excel文件导出
- spring框架的功能
- WZC框架下wifi功能的实现
- Spring+SpringMVC+MyBatis实现数据库连接的登录功能
- 关于spring+mybatis框架下包重命名的修改
- Maven管理下的Struts2+Spring+Mybatis框架搭建
- Spring mvc+mybatis框架下的TooManyResultsException异常
- 串口异步收发的实现
- easyui form表单.serialize()序列化后中文乱码问题原因及解决
- codeforces AIM Tech Round 3 (Div. 2) (A~D)
- 修改tomcat的conf/server.xml解决网页乱码
- Android--加载大分辨率图片到内存
- spring+strust2+mybatis框架下的导出功能的实现
- java反射的基本使用
- 正则表达式介绍
- 欢迎使用CSDN-markdown编辑器
- Aspose.Cells如何设置单元格数字和日期的显示格式
- 字符串指针和字符数组的又一区别
- IOS开发之MapKit学习笔记
- 加载等待动画
- python下requests的安装、测试、入门资料、官方资料