一:页面图片显示预览:

1)

2)点击导出按钮后预览:

3)最终生成的excel表格图片预览:

二:代码演示:

说明:执行操作时,请先引进导出excel表格的jar文件包,在本人的资源里面可以下载,网上搜索下载也即可,

找到导出按钮所执行的js方法,在java后天查看该方法的实现即可

1)jsp代码:

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags" %>
<%String path = request.getContextPath();String basePath = request.getScheme() + "://"+ request.getServerName() + ":" + request.getServerPort()+ path + "/";
%>
<html>
<head>
<base href="<%=basePath%>">
<title>驾校合格率排名</title><link href="jsp/commonstyle/css/tabStyle.css" rel="stylesheet" type="text/css">
<link rel="STYLESHEET" type="text/css" href="<%=basePath%>jsp/hgltj/js/tablesort.css">
<script type="text/javascript" src="<%=basePath%>jsp/system/common/js/publicColor.js"></script>
<script type="text/javascript" src="jsp/commonstyle/js/js/My97DatePicker/WdatePicker.js" defer="defer"></script>
<script type="text/javascript" src="<%=basePath%>jsp/hgltj/js/tablesort.js"></script>
<script language="JavaScript">
function load()
{
//根据分辨率设置表格大小
maxw=document.getElementById("maintb").offsetWidth;if(maxw<824){//1024分辨率未展开mainbox.width="98%";} else if(maxw<1013){//1024分辨率展开mainbox.width="98%";} else  if(maxw<1081){//1280分辨率未展开mainbox.width="95%";} else  if(maxw<1270){//1280分辨未展开mainbox.width="95%";}else{//1280以上分辨展开mainbox.width="98%";}
}
</script>
<script>
function overIt(){var the_obj = event.srcElement;if(the_obj.tagName.toLowerCase() == "td"){the_obj=the_obj.parentElement;the_obj.oBgc=the_obj.currentStyle.backgroundColor;            the_obj.oFc=the_obj.currentStyle.color;the_obj.style.backgroundColor='#4073C4';the_obj.style.color='#ffffff';the_obj.style.textDecoration='underline';}
}function outIt(){var the_obj = event.srcElement;if(the_obj.tagName.toLowerCase() == "td"){the_obj=the_obj.parentElement;the_obj.style.backgroundColor=the_obj.oBgc;the_obj.style.color=the_obj.oFc;the_obj.style.textDecoration='';}
}
function serch(){
document.getElementById("formName").action="<%=basePath %>hgltj.action?method=getHglpm";
document.getElementById("formName").submit();
}function tbbt(){
var jzrq=document.getElementById("jzrqId").value;
//var jxmc=document.getElementById("jxmcId").value;
window.open('<%=basePath %>hgltj.action?method=getHglpmTb&tjjxkshgl.jzrq='+jzrq+'&tjjxkshgl.zt='+1,'','height=650,width=1250,top=150,left=200,toobar=no,menubar=no,scrollbars=yes,resizable=no,location=no,');
}function openwd(){
document.getElementById("formName").action="<%=basePath %>hgltj.action?method=downJxhglPm";
document.getElementById("formName").submit();
}
</script>
</head>
<BODY onLoad="load()" style="background: url(images/cont_bg.gif); background-repeat: repeat-y"><input type="hidden" name="method" value="getDriverInfoList"/><table border="0" width="100%" cellspacing="0" cellpadding="0" id="maintb"><tr><td align="center"><table width="90%"  border="0"  cellspacing="0" cellpadding="0" id="mainbox" style="background:url(jsp/commonstyle/images/usermessage_02.gif); background-repeat:repeat-x;" ><!--宽度可变内容框--><tr ><td width="33" height="27" style=" background:url(jsp/commonstyle/images/usermessage_01.gif); background-position:left; background-repeat:no-repeat;" ></td><td width="965" class="style1"><font color="black">驾校合格率排名</font></td><td width="14" height="27" style=" background:url(jsp/commonstyle/images/usermessage_03.gif); background-position:right; background-repeat:no-repeat;"> </td></tr><tr><td colspan="3"><!--页面主体内容开始--><!--查询条件--><form action="" name="formName" method="post" style="margin:0px" id="formName" theme="simple"><table width="100%" border="0" cellpadding="0" cellspacing="0"   style="border-collapse:collapse;" id="tj" align="center"><tr align="left"><td class="tjbg1" style="text-align: left"><!-- <input type="hidden" id="method"  name="method" value="getHglpm"/> -->统计日期:<input type="text" name="tjjxkshgl.jzrq" id="jzrqId" value="<s:property value="tjjxkshgl.jzrq"/>" οnclick="WdatePicker({skin:'whyGreen',dateFmt:'yyyy-MM'})"/>        <!-- 驾校名称:<s:select id="jxmcId"  name="tjjxkshgl.jxxh"  value="tjjxkshgl.jxxh" list="schoolList" listKey="jxxh" listValue="jxmc" headerKey="" headerValue="--请选择--" theme="simple"></s:select>        --><input name="input" value=" 统 计 " type="button" class="normalbtn" onClick="serch()" style="margin-bottom: 5px" />        <input name="input" type="button" value=" 合格率图表 " οnclick="tbbt()" class="normalbtn" style="margin-bottom: 5px" />        <input id="Button1" type="button" value=" 导 出 " οnclick="openwd();" class="normalbtn" style="margin-bottom: 5px" /></td></tr></table><!--查询结果--></form><!--查询结果--><table width="100%" border="0" cellpadding="4" cellspacing="1" bgcolor="#abcfff" id="cxjg" align="center"><thead><tr class="tbtitle"><td width="4%" align="center" class="t1">名次</td><td width="8%" align="center" class="t1">名称</td><td class="t1" width="5%" align="center">科目一</td><td class="t1" width="5%" align="center">科目二</td><td class="t1" width="5%" align="center">科目三</td><td class="t1" width="5%" align="center">平均合格率</td><td class="t1" width="5%" align="center">操作</td></tr></thead><s:iterator id="jxhgl" value="jxhelpmList" status="st"><tr class="changeColor" onMouseOver="overIt()" onMouseOut="outIt()" style="cursor: hand" align="center"><td><s:property value="#st.index+1"/></td><td><s:property value="#jxhgl.jxmc"/></td><td><s:property value="#jxhgl.km1hgl"/></td><td><s:property value="#jxhgl.km2hgl"/></td><td><s:property value="#jxhgl.km3hgl"/></td><td><s:property value="#jxhgl.avghgl"/>%</td><td><a href="javascript:" οnclick="openWin('<%=basePath %>hgltj.action?method=getTbForJxxh&tjjxkshgl.jxxh=<s:property value="#jxhgl.jxxh"/>&tjjxkshgl.zt=1','',1250,750);">图表</a></td></tr></s:iterator></table></table></td></tr></table></body>
</html>

2)java代码演示:

/*** 驾校合格率导出excel图表*/public void downJxhglPm(){codeList=codesService.getcode("1042");//码表查值jxhelpmList=hglTjService.getJxhglpm(tjjxkshgl);//驾校合格率排名for(int i =0;i<jxhelpmList.size();i++){TjJxkshgl tt = (TjJxkshgl)jxhelpmList.get(i);tt.setJxmc(CodeUtil.getJxjcByJxxh(codeList,tt.getJxxh()));}OutputStream os=null;WritableWorkbook wbook=null;try { os = new BufferedOutputStream(response.getOutputStream());//得到输出流的语句 //response.getOutputStream();// 取得输出流   response.reset();// 清空输出流   String tmptitle = "驾校合格率排名"; // 标题   response.setHeader("Content-disposition", "attachment; filename="+new String(tmptitle.getBytes(),"iso8859-1")+".xls");// 设定输出文件头   response.setContentType("application/vnd.ms-excel");// 定义输出类型 wbook = Workbook.createWorkbook(os); // 建立excel文件   WritableSheet wsheet = wbook.createSheet(tmptitle, 0); // sheet名称  // 设置excel标题WritableFont wfont = new WritableFont(WritableFont.ARIAL, 16,WritableFont.BOLD,false,UnderlineStyle.NO_UNDERLINE,Colour.BLACK); //设置表格样式  WritableCellFormat wcfFC = new WritableCellFormat(wfont); //wcfFC.setBackground(Colour.AQUA);Label label=new Label(0, 0, tmptitle, wcfFC);    WritableCellFormat cellFormat=new WritableCellFormat();     cellFormat.setAlignment(jxl.format.Alignment.CENTRE);     cellFormat.setVerticalAlignment(jxl.format.VerticalAlignment.CENTRE); cellFormat.setWrap(true);  //cellFormat.setBackground(Colour.AQUA);cellFormat.setFont(wfont);label.setCellFormat(cellFormat);       wsheet.addCell(label);//wsheet.addCell(new Label(0, 0, tmptitle, wcfFC));wsheet.setRowView(0,500); //第一行高度wsheet.mergeCells(0, 0, 6, 1);  //合并单元格(第一列的第一行和第七列的第二行合并)    //wsheet.mergeCells(0, 1, 9, 1);
//      wsheet.mergeCells(0, 2, 0, 4);
//      wsheet.mergeCells(1, 2, 3, 2);
//      wsheet.mergeCells(4, 2, 6, 2);
//      wsheet.mergeCells(7, 2, 9, 2);     wsheet.setColumnView(0,10); //宽度wsheet.setColumnView(1,25); //宽度wsheet.setColumnView(2,10); //宽度wsheet.setColumnView(3,10); //宽度wsheet.setColumnView(4,10); //宽度wsheet.setColumnView(5,10); //宽度// 开始生成主体内容       wfont = new jxl.write.WritableFont(WritableFont.ARIAL, 14,WritableFont.BOLD,false, UnderlineStyle.NO_UNDERLINE,Colour.BLACK);   wcfFC = new WritableCellFormat(wfont);wsheet.addCell(new Label(0, 2, "名次",wcfFC));   wsheet.addCell(new Label(1, 2, "驾校名称",wcfFC));   wsheet.addCell(new Label(2, 2, "科目一",wcfFC));  wsheet.addCell(new Label(3, 2, "科目二",wcfFC));wsheet.addCell(new Label(4, 2, "科目三",wcfFC)); wsheet.addCell(new Label(5, 2, "合格率",wcfFC));  int count=jxhelpmList.size();if(count>0){  判断集合是否不为0TjJxkshgl tjhgl=null;for(int i=0;i<jxhelpmList.size();i++){ tjhgl=(TjJxkshgl)jxhelpmList.get(i);wsheet.addCell(new Label(0, i+3, (i+1)+""));wsheet.addCell(new Label(1, i+3, tjhgl.getJxmc()));wsheet.addCell(new Label(2, i+3, tjhgl.getKm1hgl()));wsheet.addCell(new Label(3, i+3, tjhgl.getKm2hgl()));wsheet.addCell(new Label(4, i+3, tjhgl.getKm3hgl()));wsheet.addCell(new Label(5, i+3, tjhgl.getAvghgl()));}}   wbook.write(); // 写入文件  }catch(Exception ex) { ex.printStackTrace(); }finally{if(os!=null){try {os.close();} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();}}if(wbook!=null){try {wbook.close();} catch (WriteException e) {// TODO Auto-generated catch blocke.printStackTrace();} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();}}} }

天易26----java导出excel表格(支持wps和office excel)相关推荐

  1. excel怎么启用宏_轻便免费的Excel合并工具,支持wps和office全系统

    Excel合并工具绿色程序版是一款由吾爱网友ermituofo分享制作的Excel合并软件,软件支持wps和office全系统,很多用户发表格给其他用户之后自己要使用合并处理就很麻烦,有了这个工具,就 ...

  2. php wps导入数据库,wps excel表格怎么导入数据库-如何把excel表格导入wps

    wps怎么将excel表格导入word 在word中的菜单栏选择"插入"--"对象"--选择"新建"或者"由对象创建". ...

  3. java使用jxl生成excel表格,jsp使用js下载excel文件xls

    java使用jxl生成excel表格,jsp使用js下载excel文件 后端代码 maven jar包 主体代码逻辑 引入的jar包 具体代码段 重点详解 表头和表格内容两种格式 直接将 HttpSe ...

  4. SAP 导出 HTML,【我sap这导出数据表格export.mhtml怎么转换为 excel 工作表.xlsx】excel生成html表格数据...

    如何把Html网页格式转成Excel表格 1.单击数据--导部数据--新建Web查询. 2.勾选我可以此内容,允许播放,单击继续按钮. 3.在地址栏输入网站地址,转到此网站里面. 4.跳转到指定网页, ...

  5. Jquery导出页面表格table的内容为Excel,PDF,DOC格式

    Jquery导出页面表格table的内容为Excel,PDF,DOC格式 文档地址:http://www.jqueryfuns.com/resource/2381 1.引入jquery的js–这里就不 ...

  6. Java导出word表格|poi-tl

    目标 多级表头.分页.动态数据 实现 依赖: <!-- poi工具类--><dependency><groupId>com.deepoove</groupId ...

  7. php页面导入excel表格,php页面导入excel表格数据:php导入excel 怎么获取excel表格数据...

    导入excel文件,后端php处理导入的数据并存入数据库,需要前后端结合的demo! thinkphp3.2phpexcel导入最基本用法 先整个最基础的代码,理解了这个,后面非常简单了 $file_ ...

  8. oracle 导入excel时间格式,excel表格导入时间数据库中-excel导入数据库,我的日期是datatime()自动生成......

    如何将excel表格数据导入到oracle数据库对应的表中? 假定a1是你的mysql中的时间戳,要在B1取得普通的时间表示,则b1= =25569 A1*0.0000115743621516652 ...

  9. 办公软件excel表格_钢筋算量Excel表格,现场算钢筋,效率可与大型软件相比

    提起钢筋算量,工作很久造价和施工恐怕都要挠头,对于刚入行的造价和施工都可以说是灾难.不过不用担心,我今天就是来给大家送解决方法--钢筋算量Excel表格. 钢筋算量Excel表格基本包含了钢筋算量的全 ...

最新文章

  1. java构造方法 this_Java之构造方法及this、super关键字
  2. python自带的shell是什么-python shell是什么东西
  3. 《第一行代码》学习笔记18-广播接收器Broadcast_Receiver(1)
  4. mysql --explicit_【MySQL】 explicit_defaults_for_timestamp 参数解析
  5. isDate()函数
  6. Linux 在 M1 上跑起来了
  7. 巧妙的实现 CSS 斜线
  8. 批量发送邮件的软件——邮件群发机器人
  9. wingftpserver完整配置免费ftp站点(指南)
  10. 三分钟搭建单节点私链教程
  11. Java关于日志,及日志的error和warn的选择
  12. 中学-综合素质【2】
  13. 如何使用xbrowser图形化连接centos
  14. 观察者模式Observer -- 深入理解
  15. python多张图叠加为一张_python实现多张图片拼接成大图
  16. NASM汇编语言与计算机系统10-中断向量表0号中断(cli/sti/iret/hlt)
  17. win10安装node后报错:npm WARN config global `--global`, `--local` are deprecated. Use `--location=global`
  18. 本地搭建靶站进行漏洞复现和防御(SQL注入、文件上传、XSS漏洞的多种形式)
  19. ZDNS发布国际标准IETF RFC 8897,网络根基安全升级迈出关键一步
  20. 【PS2019CC】工具栏找不到某工具怎么办/自定义工具栏的步骤

热门文章

  1. Inter VT技术(硬件虚拟化检测)
  2. 微积分位于基础数学的核心部分
  3. eWebEditor的使用方法
  4. 直流电机/步进电机/伺服电机 简介
  5. c语言版数据结构期末考试试题及答案,数据结构c语言版期末考试复习试题[1]
  6. 8个超好用的免费工具/软件/网站(一定有你要的)
  7. linux按大小显示当前文件,linux下按文件大小排序
  8. 攻防世界 简单的base编码
  9. Arcmap设置经纬网只显示度不显示分
  10. 《浪潮之巅》作者吴军万字长文:中国算力的危与机