发布时间:2026/7/28 14:40:24
将查询的集合导出为Excel文件 第一个是前台的script的代码第二个是servlet中控制xml下载的代码这里直接复制黏贴拿来修改一下就好了可以设置一个按钮访问这个servletmethodexportXls就可以啦function exportXls(){ var empId$(#empId).val(); var deptNo$(#deptNo).val(); var dtdate$(#dtdate).val(); location.hrefservlet/DutyServlet?methodexportXlsempIdempIddeptNodeptNodtdatedtdate; }public void exportXls(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { //接收网页中参数 String empIdrequest.getParameter(empId); if(empIdnull){ empId; } String cdeptNorequest.getParameter(deptNo); int deptNo0; try{ deptNoInteger.parseInt(cdeptNo); }catch (Exception e){ } String dtdaterequest.getParameter(dtdate); if(dtdatenull){ dtdate; } DutyService dutyServicenew DutyServiceImple(); //查询数据库将所有符合的信息放到一个集合中 ListDutydutyListdutyService.find(empId,deptNo,dtdate); //调用该方法传一个集合和response响应 createExcel(dutyList,response); } private void createExcel(ListDuty dutyList, HttpServletResponse response) { // 创建一个Excel文件 HSSFWorkbook workbook new HSSFWorkbook(); // 创建一个工作表 HSSFSheet sheet workbook.createSheet(签到表一); CellRangeAddress region new CellRangeAddress(0, // first row 0, // last row 0, // first column 2 // last column ); sheet.addMergedRegion(region); HSSFRow hssfRow sheet.createRow(0); HSSFCell headCell hssfRow.createCell(0); headCell.setCellValue(员工签到表); // 设置单元格格式居中 HSSFCellStyle cellStyle workbook.createCellStyle(); cellStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER); /* cellStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); // cellStyle.setFillBackgroundColor(HSSFColor.GREEN.index); cellStyle.setFillForegroundColor(HSSFColor.GREEN.index); HSSFFont font workbook.createFont(); font.setFontName(楷体); //字体 font.setFontHeightInPoints((short)30); //字体大小 font.setColor(HSSFColor.RED.index);//颜色 font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);//加粗 font.setItalic(true); //倾斜 cellStyle.setFont(font); */ headCell.setCellStyle(cellStyle); // 添加表头行 hssfRow sheet.createRow(1); // 添加表头内容 headCell hssfRow.createCell(0); headCell.setCellValue(用户名); headCell.setCellStyle(cellStyle); headCell hssfRow.createCell(1); headCell.setCellValue(真实姓名); headCell.setCellStyle(cellStyle); headCell hssfRow.createCell(2); headCell.setCellValue(所属部门); headCell.setCellStyle(cellStyle); headCell hssfRow.createCell(3); headCell.setCellValue(出勤日期); headCell.setCellStyle(cellStyle); headCell hssfRow.createCell(4); headCell.setCellValue(签到时间); headCell.setCellStyle(cellStyle); headCell hssfRow.createCell(5); headCell.setCellValue(签退时间); headCell.setCellStyle(cellStyle); // 添加数据内容 for (int i 0; i dutyList.size(); i) { hssfRow sheet.createRow((int) i 2); Duty duty dutyList.get(i); // 创建单元格并设置值 HSSFCell cell hssfRow.createCell(0); cell.setCellValue(duty.getEmpId()); cell.setCellStyle(cellStyle); cell hssfRow.createCell(1); cell.setCellValue(duty.getEmployee().getRealName()); cell.setCellStyle(cellStyle); cell hssfRow.createCell(2); cell.setCellValue(duty.getDept().getDeptName()); cell.setCellStyle(cellStyle); cell hssfRow.createCell(3); cell.setCellValue(duty.getDtDate()); cell.setCellStyle(cellStyle); cell hssfRow.createCell(4); cell.setCellValue(duty.getSignInTime()); cell.setCellStyle(cellStyle); cell hssfRow.createCell(5); cell.setCellValue(duty.getSignOutTime()); cell.setCellStyle(cellStyle); } // 保存Excel文件 try { response.setContentType(application/vnd.ms-excel); response.setHeader(Content-disposition,attachment;filenameduty.xls); OutputStream outputStream response.getOutputStream(); workbook.write(outputStream); outputStream.close(); } catch (Exception e) { e.printStackTrace(); } }

相关新闻

2026/7/28 14:40:24

Palworld存档修复工具:告别角色丢失,轻松迁移游戏数据

Palworld存档修复工具:告别角色丢失,轻松迁移游戏数据 【免费下载链接】palworld-host-save-fix Fixes the bug which forces a player to create a new character when they already have a save. Useful for migrating maps from co-op to dedicated s…

2026/7/28 14:40:24

200+插件一站式增强:HF Patch带你解锁《恋活!》完整潜力

200插件一站式增强:HF Patch带你解锁《恋活!》完整潜力 【免费下载链接】KK-HF_Patch Automatically translate, uncensor and update Koikatu! and Koikatsu Party! 项目地址: https://gitcode.com/gh_mirrors/kk/KK-HF_Patch 你是否曾经觉得《恋…

2026/7/28 15:45:30

Matlab仿真实现垂直泊车路径规划算法解析

1. 垂直泊车路径规划与自动泊车仿真概述垂直泊车是自动泊车系统(APS)中最具挑战性的场景之一,需要车辆在有限空间内完成精确的横向移动和角度调整。Matlab/Simulink因其强大的数值计算和可视化能力,成为验证泊车算法的首选工具。我在汽车电子行业参与过多…

2026/7/28 15:45:30

网络编程-part1-三次握手-四次挥手

三次握手和四次挥手在面试考网络方面的只是经常看见,大家一定要谨记于心。 TCP三次握手过程如下: C-> SYN -> S S->SYN/ACK->C C->ACK->S三次握手:Client将标志位SYN置为1,随机产生一个值seqJ,并将该…

2026/7/28 15:45:30

数据分析自学指南:从Excel到Python,掌握四大核心技能

很多同学在入门数据分析时,常常感到迷茫:Excel、SQL、Tableau、Python……工具这么多,到底该从哪学起?网上资料零散不成体系,学了很久还是做不出像样的分析报告,更别提在求职面试中脱颖而出了。本文为你梳理…

2026/7/28 15:45:30

Git克隆代码No such file or directory或需要password

问题有时候git bash here 时,会出现克隆代码失败的问题。 其中有可能的原因是SSH Key已经过期,需要重新建一个。 如何设置SSH Key 1、右击git bash here,命令行输入 $ git config --global user.name “li” //配置用户名 $ git config --glo…

2026/7/28 13:41:25

PDF合并与动态水印的工程化方案:2026国内免费工具实测对比

一、背景与测试方案 在实际项目交付中,PDF文件合并与版权保护水印的叠加是一个高频但容易被低估的技术需求。典型的处理链路涉及:多源PDF的文件流合并、页面级水印渲染(含透明度混合与图层叠加)、输出文件体积控制。看似简单的操作…

2026/7/28 0:03:34

学术论文研究创新点梳理与核心价值提炼指南

本科毕业论文是大学四年最大的坎。开题报告憋一周写不出三页,找文献翻遍十几个网站还是缺关键资料,写正文卡壳半天憋不出一句话,降重改到凌晨三点结果逻辑全乱,答辩前一天PPT还没做完。别慌,亲测这四个工具能让你少熬半…

2026/7/28 0:03:34

开发商售楼处数字化升级怎么做?

房企的数字化转型投入正在快速增长,据行业数据显示,2025年房企数字化投入规模已突破800亿元,年复合增长率达35%。售楼处的数字化升级不是单一环节的改造,而是从“获客-展示-成交-服务”全链路的系统升级。数字化升级四步法第一步&…

2026/7/28 0:03:34

模型不再值钱之后,AI 编程工具在争什么

2026 年 7 月,AI 编程工具赛道发生了一个标志性转折:模型本身不再值钱了。当 Kimi K3 开源模型在编程基准上击败 GPT 和 Claude,当 GitHub Copilot 第一次把开源模型纳入选择器,当 OpenAI 把 Codex 并入 ChatGPT 做成三合一超级应…

2026/7/28 4:38:09

3个高效策略:快速掌握Axure中文界面配置

3个高效策略:快速掌握Axure中文界面配置 【免费下载链接】axure-cn Chinese language file for Axure RP. Axure RP 简体中文语言包。支持 Axure 11、10、9。不定期更新。 项目地址: https://gitcode.com/gh_mirrors/ax/axure-cn 还在为Axure RP的英文界面感…