将jsp页面的table报表转换到excel报表导出

来源:互联网 发布:东华大学数据库 编辑:程序博客网 时间:2024/04/29 20:58

一. 直接将Table导出到Excel,不用导入任何第三方包

<%@ page language="java" contentType="text/html; charset=utf-8"    pageEncoding="utf-8"%><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>Export to Excel - Demo</title></head><body>    <%        String exportToExcel = request.getParameter("exportToExcel");        if (exportToExcel != null                && exportToExcel.toString().equalsIgnoreCase("YES")) {            response.setContentType("application/vnd.ms-excel");            response.setHeader("Content-Disposition", "inline; filename="                    + "excel.xls");        }    %>    <table align="left" border="2">        <thead>            <tr bgcolor="lightgreen">                <th>Sr. No.</th>                <th>Text Data</th>                <th>Number Data</th>            </tr>        </thead>        <tbody>            <%                for (int i = 0; i < 10; i++) {            %>            <tr bgcolor="lightblue">                <td align="center"><%=i + 1%></td>                <td align="center">This is text data <%=i%></td>                <td align="center"><%=i * i%></td>            </tr>            <%                }            %>        </tbody>    </table>    <br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>    <%        if (exportToExcel == null) {    %>    <a href="MyJsp.jsp?exportToExcel=YES">Export to Excel</a>    <%        }    %></body></html>
0 0
原创粉丝点击