一:页面显示预览:
1)如下图:
2)点击导出按钮后预览:
3)最终生成的excel表格预览:
二:代码演示:
说明:执行 *** 作时,请先引进导出excel表格的jar文件包。
找到导出按钮所执行的js方法,在java后天查看该方法的实现即可。
1)jsp代码:
[html] view plaincopyprint
<%@ page language="java" import="javautil" pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags" %>
<%
String path = requestgetContextPath();
String basePath = requestgetScheme() + "://"
+ requestgetServerName() + ":" + requestgetServerPort()
+ path + "/";
%>
<html>
<head>
<base href="<%=basePath%>">
<title>驾校合格率排名</title>
<link href="jsp/commonstyle/css/tabStylecss" rel="stylesheet" type="text/css">
<link rel="STYLESHEET" type="text/css" href="<%=basePath%>jsp/hgltj/js/tablesortcss">
<script type="text/javascript" src="<%=basePath%>jsp/system/common/js/publicColorjs"></script>
<script type="text/javascript" src="jsp/commonstyle/js/js/My97DatePicker/WdatePickerjs" defer="defer"></script>
<script type="text/javascript" src="<%=basePath%>jsp/hgltj/js/tablesortjs"></script>
<script language="JavaScript">
function load()
{
//根据分辨率设置表格大小
maxw=documentgetElementById("maintb")offsetWidth;
if(maxw<824){//1024分辨率未展开
mainboxwidth="98%";
} else if(maxw<1013){//1024分辨率展开
mainboxwidth="98%";
} else if(maxw<1081){//1280分辨率未展开
mainboxwidth="95%";
} else if(maxw<1270){//1280分辨未展开
mainboxwidth="95%";
}else{//1280以上分辨展开
mainboxwidth="98%";
}
}
</script>
<script>
function overIt(){
var the_obj = eventsrcElement;
if(the_objtagNametoLowerCase() == "td"){
the_obj=the_objparentElement;
the_objoBgc=the_objcurrentStylebackgroundColor;
the_objoFc=the_objcurrentStylecolor;
the_objstylebackgroundColor='#4073C4';
the_objstylecolor='#ffffff';
the_objstyletextDecoration='underline';
}
}
function outIt(){
var the_obj = eventsrcElement;
if(the_objtagNametoLowerCase() == "td"){
the_obj=the_objparentElement;
the_objstylebackgroundColor=the_objoBgc;
the_objstylecolor=the_objoFc;
the_objstyletextDecoration='';
}
}
function serch(){
documentgetElementById("formName")action="<%=basePath %>hgltjactionmethod=getHglpm";
documentgetElementById("formName")submit();
}
function tbbt(){
var jzrq=documentgetElementById("jzrqId")value;
//var jxmc=documentgetElementById("jxmcId")value;
windowopen('<%=basePath %>hgltjactionmethod=getHglpmTb&tjjxkshgljzrq='+jzrq+'&tjjxkshglzt='+1,'','height=650,width=1250,top=150,left=200,toobar=no,menubar=no,scrollbars=yes,resizable=no,location=no,');
}
function openwd(){
documentgetElementById("formName")action="<%=basePath %>hgltjactionmethod=downJxhglPm";
documentgetElementById("formName")submit();
}
</script>
</head>
<BODY onLoad="load()" style="background: url(images/cont_bggif); 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_02gif); background-repeat:repeat-x;" >
<!--宽度可变内容框-->
<tr >
<td width="33" height="27" style=" background:url(jsp/commonstyle/images/usermessage_01gif); 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_03gif); 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="tjjxkshgljzrq" id="jzrqId" value="<s:property value="tjjxkshgljzrq"/>" onclick="WdatePicker({skin:'whyGreen',dateFmt:'yyyy-MM'})"/>
<!-- 驾校名称:
<s:select id="jxmcId" name="tjjxkshgljxxh" value="tjjxkshgljxxh" 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=" 合格率图表 " onclick="tbbt()" class="normalbtn" style="margin-bottom: 5px" />
<input id="Button1" type="button" value=" 导 出 " onclick="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="#stindex+1"/></td>
<td><s:property value="#jxhgljxmc"/></td>
<td><s:property value="#jxhglkm1hgl"/></td>
<td><s:property value="#jxhglkm2hgl"/></td>
<td><s:property value="#jxhglkm3hgl"/></td>
<td><s:property value="#jxhglavghgl"/>%</td>
<td>
<a href="javascript:" onclick="openWin('<%=basePath %>hgltjactionmethod=getTbForJxxh&tjjxkshgljxxh=<s:property value="#jxhgljxxh"/>&tjjxkshglzt=1','',1250,750);">图表</a>
</td>
</tr>
</s:iterator>
</table>
</table>
</td>
</tr>
</table>
</body>
</html>
2)java代码演示:
[java] view plaincopyprint
/
驾校合格率导出excel图表
/
//responsegetOutputStream();// 取得输出流
responsereset();// 清空输出流
String tmptitle = "驾校合格率排名"; // 标题
responsesetHeader("Content-disposition", "attachment; filename="+new String(tmptitlegetBytes(),"iso8859-1")+"xls");// 设定输出文件头
responsesetContentType("application/vndms-excel");// 定义输出类型
wbook = WorkbookcreateWorkbook(os); // 建立excel文件
WritableSheet wsheet = wbookcreateSheet(tmptitle, 0); // sheet名称
// 设置excel标题
//cellFormatsetBackground(ColourAQUA);
cellFormatsetFont(wfont);
labelsetCellFormat(cellFormat);
wsheetaddCell(label);
//wsheetaddCell(new Label(0, 0, tmptitle, wcfFC));
wsheetsetRowView(0,500); //第一行高度
wsheetmergeCells(0, 0, 6, 1); //合并单元格(第一列的第一行和第七列的第二行合并)
//wsheetmergeCells(0, 1, 9, 1);
// wsheetmergeCells(0, 2, 0, 4);
// wsheetmergeCells(1, 2, 3, 2);
// wsheetmergeCells(4, 2, 6, 2);
// wsheetmergeCells(7, 2, 9, 2);
wsheetsetColumnView(0,10); //宽度
wsheetsetColumnView(1,25); //宽度
wsheetsetColumnView(2,10); //宽度
wsheetsetColumnView(3,10); //宽度
wsheetsetColumnView(4,10); //宽度
wsheetsetColumnView(5,10); //宽度
// 开始生成主体内容
wfont = new jxlwriteWritableFont(WritableFontARIAL, 14,WritableFontBOLD,false, UnderlineStyleNO_UNDERLINE,ColourBLACK);
wcfFC = new WritableCellFormat(wfont);
wsheetaddCell(new Label(0, 2, "名次",wcfFC));
wsheetaddCell(new Label(1, 2, "驾校名称",wcfFC));
wsheetaddCell(new Label(2, 2, "科目一",wcfFC));
wsheetaddCell(new Label(3, 2, "科目二",wcfFC));
wsheetaddCell(new Label(4, 2, "科目三",wcfFC));
wsheetaddCell(new Label(5, 2, "合格率",wcfFC));
int count=jxhelpmListsize();
if(count>0){ ////判断集合是否不为0
TjJxkshgl tjhgl=null;
for(int i=0;i<jxhelpmListsize();i++){
tjhgl=(TjJxkshgl)jxhelpmListget(i);
wsheetaddCell(new Label(0, i+3, (i+1)+""));
wsheetaddCell(new Label(1, i+3, tjhglgetJxmc()));
wsheetaddCell(new Label(2, i+3, tjhglgetKm1hgl()));
wsheetaddCell(new Label(3, i+3, tjhglgetKm2hgl()));
wsheetaddCell(new Label(4, i+3, tjhglgetKm3hgl()));
wsheetaddCell(new Label(5, i+3, tjhglgetAvghgl()));
}
新建或打开wps excel软件
在上面数据栏内E2开始输入
=INDEX(A:A,SMALL(IF($C$2:$C$100>=70,ROW($2:$100),1000),ROW(1:1)))&""
先按住 CTRL+SHIFT,
最后回车
公式右拉下拉,如图
完成~
left函数,从文本的左侧提取一定长度的值。=left(目标文本,提取文本长度)
mid函数,从文本中提取一定长度的值。=mid(目标文本,第几个字符开始提取,提取文本长度)
right函数,从文本的右侧提取一定长度的值。=right(目标文本,提取文本长度)
以上就是关于如何将xls文件保存为BDF文件全部的内容,包括:如何将xls文件保存为BDF文件、mysql数据库中的表格数据如何导入wps中的excel,请问该怎么去做、用java将数据导出到wps表格中,怎么实现等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)