Java Export Excel

Source: Internet
Author: User

!!! The util used in the declaration are described in the Baidu Cloud Http://pan.baidu.com/s/1mibbL8W if expired please add QQ 1940978083

1. Add HTML

<form action= "<%=path%>/black/exportexcel.html"    //Here Backstage address onsubmit= "return CheckUser ();" ><div class= "panel-heading" ><div class= "row" ><div class= "col-lg-3 col-md-3 col-xs-3" style= " margin-right:0px;padding-right:0px; " ><form class= "Form-inline" ><div class= "Form-group" ><div class= "Input-group" ><div class= " Input-group-addon "> Blacklist number </div><input type=" text "class=" Form-control input-sm "id=" name "Name=" Blackname "></div></div></form>

  

2.

@RequestMapping ("Exportexcel") public void Exportexcel (HttpServletRequest req, httpservletresponse Res) throws Exception {domain domain = (domain) req.getsession (). getattribute ("Domainlogin"); String name = Req.getparameter ("Blackname"), if (name = = null) {name = "";} list<blacklist> list = Blacklistservice.findallnumber (Domain.getdomainid (), name); Res.reset (); Res.setcontenttype ("Application/vnd.ms-excel;charset=utf-8"); Res.setcontenttype ("Application/x-xls");// Defines the output type string date = Dateutil.datetostringt (new date ()), Res.setheader ("Content-disposition", "attachment;filename=" + Date + ". xls"); excelexportutil<blacklist> exportutil = new excelexportutil<blacklist> ();   String[] headers = {"id", "Creation Time", "Blacklist number"}; string[] columns = {"id", "createtime", "number"};outputstream OutputStream = Res.getoutputstream (); Exportutil.expoortexcelx ("Blacklist", headers, columns, list, OutputStream, "Yyyy-mm-dd HH:mm:ss"); Outputstream.flush (); O Utputstream.close ();}

Explanation headers is a field that exports Excel column names columns is the corresponding database

 

Java Export 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.