JSP export Excel full instance plus source code

Source: Internet
Author: User

在java web项目中经常会进行excel的导入导出,今天介绍一种非常简洁不需要额外的jar的excel导出方式。导出的源码demo下载下来后直接在tomcat中即可运行。源码:链接: 链接: http://pan.baidu.com/s/1bnD8mrd 密码: 59dh (有的时候百度网盘的链接会莫名其妙失效,如果该链接失效,请留言,我看到后会重发)。导出excel一般是:通过查询条件---选定特定的数据--点击导出。实现思路如下:在jsp页面首先需要加入:
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%><%    response.setHeader("Content-disposition",            "attachment; filename=BG.xls");    response.setHeader("Pragma", "");    response.setHeader("Cache-Control", "");%>

Then there is the list loop, with the following code:

<table>        <thead>            <tr>                <TD>Serial number</td>                <TD>Name</td>                <TD>Gender</td>                <TD>Age</td>                <TD>ID number</td>            </tr>        </thead>        <tbody>  <c:foreach Items="${listperson}" var="User"  Varstatus="status">                <tr>                    <TD>${STATUS.INDEX+1}</td>                    <TD>${user.name}</td>                    <TD>${user.sex}</td>                    <TD>${user.age}</td>                    <TD>${user.idcard}</td>                </tr> </C:foreach>        </tbody>    </table>

Finally, the CSS style code for the table:

/ * table has a border * /Table,th,TD {  border: 1px solid #000;} / * The text in the table is centered up or down * /TD {  text-align: center;  vertical-align: Middle; }/ * Show scientific notation in order to resolve export ID * /TD {  mso-number-format: ' \@ ';} 

In this way, the JSP can be exported in Excel, detailed reference to Excel exported demo.

JSP export Excel full instance plus source code

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.