Use jsp to export the complete EXCEL instance and add source code

Source: Internet
Author: User

Use jsp to export the complete EXCEL instance and add source code

In java web projects, excel is often imported and exported. Today we will introduce a very simple excel export method without the need for additional jar. Download the exported source code demo and run it directly in tomcat. Source code: Link: http://pan.baidu.com/s/1bnD8mrd password: 59dh (sometimes Baidu Network Disk link will be inexplicably invalid, if the link is invalid, please leave a message, I will resend after seeing ). To export an excel file, you can use the query condition, select a specific data, and click Export. The implementation idea is as follows: you must first add the following to the jsp page:
<%@ 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 a list loop. The specific code is as follows:


                  
  
  
  
Serial number Name Gender Age ID card number
$ {Status. index + 1} $ {User. name} $ {User. sex} $ {User. age} $ {User. idCard}

Finally, the css style code of the table is as follows:

/* The table has a border */table, th, td {border: 1px solid #000;}/* The text in the table is centered from top to bottom */td {text-align: center; vertical-align: middle;}/* display scientific notation */td {mso-number-format :'\@';}

In this way, jsp can be exported in excel. For details, refer to the demo exported in excel.

Related Article

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.