下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、JavaWeb SSH JXL 导出ExcelJsp:function aaa() / 提交方式一定不能为ajax,否则不会出现保存对话框 var frm=document.getElementById(searchwmsgform); frm.action=/select.do?dispatch=exportExcel; frm.submit();Action:/* * 导出Excel * param mapping * param form * param request * param response * return */public ActionForward exportExce
2、l(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) try String filePath = request.getRealPath(/);File file = new File(filePath + 报警信息.xls);WritableWorkbook wwb = Workbook.createWorkbook(file); /生成ExcelselectService.exportExcel(wwb);try /创建一个缓冲输入流对象 Buf
3、feredInputStream br = new BufferedInputStream( new FileInputStream(file); byte buf = new byte1024; int len = 0; response.reset(); / 非常重要 response.setContentType(application/x-msdownload); response.setHeader(Content-Disposition, attachment; filename= + new String(file.getName().getBytes(),iso-8859-1)
4、;/创建输出流对象 OutputStream outStream = response.getOutputStream(); /开始输出 while (len = br.read(buf) 0) outStream.write(buf, 0, len); /关闭流对象 br.close(); outStream.close(); catch (FileNotFoundException e) e.printStackTrace(); catch (IOException e) e.printStackTrace(); if (file.exists() /下载完毕删除文件 file.delet
5、e(); catch (Exception e) / TODO Auto-generated catch blocke.printStackTrace();return null;实现类中:public void exportExcel(WritableWorkbook book) throws Exception try WritableSheet sheet = book.createSheet(第一页, 0);/字段字体jxl.write.WritableFont wfc1 = new jxl.write.WritableFont( WritableFont.ARIAL, 13, Wri
6、tableFont.BOLD, false); jxl.write.WritableCellFormat wcfFC1 = new jxl.write.WritableCellFormat(wfc1); /水平居中wcfFC1.setAlignment(jxl.format.Alignment.CENTRE); /垂直居中wcfFC1.setVerticalAlignment(jxl.format.VerticalAlignment.CENTRE); /边框wcfFC1.setBorder(Border.ALL, BorderLineStyle.THIN);String title = 序号,
7、时间,源IP地址,目标IP地址,源MAC地址,目标MAC地址,错误信息;String splitsTitle = title.split(,);int length = splitsTitle.length;for (int i = 0; i length; i+) sheet.addCell(new jxl.write.Label(i,0,splitsTitlei,wcfFC1);/ 设置单元格的宽度 sheet.setColumnView(0, 5); sheet.setColumnView(1, 20); sheet.setColumnView(2, 15); sheet.setColu
8、mnView(3, 15); sheet.setColumnView(4, 20); sheet.setColumnView(5, 20);sheet.setColumnView(6, 15); jxl.write.WritableFont wfc2 = new jxl.write.WritableFont(WritableFont.ARIAL,10,WritableFont.NO_BOLD,false);jxl.write.WritableCellFormat wcfFC2 = new jxl.write.WritableCellFormat(wfc2);wcfFC2.setAlignmen
9、t(jxl.format.Alignment.CENTRE);wcfFC2.setVerticalAlignment(jxl.format.VerticalAlignment.CENTRE);wcfFC2.setBorder(Border.ALL, BorderLineStyle.THIN);/数据int c = 1;String sqlStr = select w_data,ip_src,ip_tar,mac_src,mac_tar,wtype from wmsg where 1=1 ;List list = auditMDao.getRsBySql(sqlStr);for (int i =
10、 0; i list.size(); i+) Object msg = (Object) list.get(i);String date = msg0.toString();String ip_src = msg1.toString();String ip_tar = msg2.toString();String mac_src = msg3.toString();String mac_tar = msg4.toString();String wtype = msg5.toString();Label content1 = new Label(0,c,c+,wcfFC2);Label cont
11、ent2 = new Label(1,c,date,wcfFC2);Label content3 = new Label(2,c,ip_src,wcfFC2);Label content4 = new Label(3,c,ip_tar,wcfFC2);Label content5 = new Label(4,c,mac_src,wcfFC2);Label content6 = new Label(5,c,mac_tar,wcfFC2);Label content7 = new Label(6,c,wtype,wcfFC2);sheet.addCell(content1);sheet.addCell(content2);sheet.addCell(c
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 认识自我趣味活动方案
- 行业精英招募活动方案
- 消毒作业指导书
- 南京市2022年中考语文模拟试卷解析
- 裂变邀请活动方案
- 蛙跳接力活动方案
- 街办垃圾分类活动方案
- 观看榜样写活动方案
- 装修公司乔迁开业活动方案
- 设计活动优惠活动方案
- 2025河南许昌禹州市招聘巡防队员120人考试参考试题及答案解析
- 2025年车管12123学法减分考试题及答案
- 2025北京市大兴区旧宫镇招聘编外用工人员16人备考考试题库附答案解析
- 2024年人教PEP版小学三年级下册英语教学计划及进度表(三年级起点)
- 2025年6月16日更新的第34批REACH250项高度关注物质SVHC清单
- 2025年(完整版)全国高考一卷数学试题及答案
- 读书分享成品-绿色卡通风假如给我三天光明好书分享模板课件
- 小学教育中的教育惩戒问题及对策研究
- 肿瘤干细胞课件
- 高警示药物培训课件
- 江苏省苏州市2024-2025学年高二上学期期中考试地理试卷(含答案)
评论
0/150
提交评论