日期:2014-05-16  浏览次数:20385 次

excel文件的页面(jsp)输出!

<%@ page language="java" contentType="text/html; charset=GBK"? pageEncoding="GBK"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://www.ecside.org" prefix="ec"%>
<%@ page import="java.util.Date"%>
<%@ page import="java.text.SimpleDateFormat"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt_rt" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@page import="java.util.Calendar,java.util.*,
????java.io.*,jxl.*,javax.servlet.ServletContext"
%>
<html >
<head>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=MS950">
<link rel="stylesheet" Content-type="text/css" href="../../css/webber.css">
<script language="JavaScript" src="lib/prototype/prototype.js"></script>
<%
String fileName = (String) request.getAttribute("fileName");
%>
<script language="JavaScript">
?function exportExcel()
{
?var url =? "download.jsp?fileName=" + "<%=fileName%>";
?window.location.href(url);
}
?
</script>

<title>各功能访问情况比例统计</title>

<jsp:include page="../common_head.jsp" flush="true" />


</head>

<body >
<table align=center class=listFrame cellspacing=1 cellpadding=0
?width="85%">
?<tbody>
??<tr align="right">
???<td ><INPUT
????type="button" class="funButton" value=" 导出Excel " onclick="exportExcel()">&nbsp;&nbsp;&nbsp;</td>
??</tr>
??<tr>
???<td?? colspan=21
????style="font-size: 16px; line-height: 30px; BACKGROUND-COLOR: #bddbf7"><b><c:out
????value="${title}" /></b></td>
??</tr>
?</tbody>
</table>
<div id="div1" style="scroll:auto;overflow:auto;width:100%;letter-spacing:0.2em;height:450px;top:100px;left:50px">
<table align=center class=listFrame cellspacing=1 cellpadding=0 width="85%">
???? <%
???? ?fileName = (String) request.getAttribute("fileName");
???? ?String filePath = application
???? ???.getRealPath("/report/"
???? ???+ fileName);
???? ?FileInputStream finput = new FileInputStream(filePath);
???? ?Workbook wbook;
???? ?wbook = Workbook.getWorkbook(finput);
???? ?Sheet wsheet = (Sheet) wbook.getSheet(0);
???? ?finput.close();
???? ?Cell[] rowcell = null;
???? ?Cell cell = null;
???? ?short i = 0;
???? ?short y = 0;
???? ?for (i = 0; i < wsheet.getRows(); i++) {
???? ??out.println("<tr>");
???? ??rowcell = wsheet.getRow(i);

???? ??for (y = 0; y < rowcell.length; y++) {
???? ???cell = rowcell[y];
???? ???out.print("<td? class=listContent>");
???? ???cell.getCellFormat().getFont().getBoldWeight();
???? ???//字体宽度
???? ???int bw = cell.getCellFormat().getFont().getBoldWeight();
???? ???
???? ???if (null != cell) {
???? ????if(bw == 700)
???????? ???{
???? ?????out.print("<b>"+cell.getContents().replace("? ","&nbsp;&nbsp;")+"</b>");
???????? ???}else{
???????? ????out.print(cell.getContents().replace("? ","&nbsp;&nbsp;"));
???????? ???}
???? ????
???? ???}

???? ???out.println("</td>");
???? ??}
???? ??out.println("</tr>");
???? ?}
???? %>
</table>
</div>
</body>
</html>