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.