Java Excel Export

Source: Internet
Author: User

Here is the JSP code:

<li class= "Btns" ><input id= "Btnexport" class= "btn btn-primary"                type= "button" value= "Export All" onclick= "exports ()"/></li>
function exports () {          top.$.jbox.confirm ("Confirm that you want to export all data?") "," System Prompt ",function(v,h,f) {            if(v==" OK ") {            $ (" #searchForm "). attr (" Action "," ${ctx}/record/record/record/export ");            $ ("#searchForm"). Submit ();            }            },{buttonsfocus:1});            top.$ ('. Jbox-body. Jbox-icon '). CSS (' top ', ' 55px ');              }

Here is the controller code: I am exporting one-to-many and passing in an entity class:

@RequestMapping (value = "Export")      PublicString Exportfile (record record, httpservletrequest request, httpservletresponse response, Redirectattributes Redirectattributes) {Try{String FileName= "User Data" +dateutils.getdate ("YYYYMMDDHHMMSS") + ". xlsx"; Page<Record> page = Recordservice.findrecord (NewPage<record> (Request, response,-1), record); NewExportexcel ("User Data", Record.class). Setdatalist (Page.getlist ()). Write (response, fileName). Dispose (); return NULL; } Catch(Exception e) {addmessage (redirectattributes,"Export failed!" Failure message: "+e.getmessage ()); }        return"Redirect:" + AdminPath + "/record/record/record?repage"; }    

Service Layer:

     Public Page<record> FindRecord (page<record> Page, record Record) {        //  Generate Data permission filters (DSF is shorthand for datascopefilter, use ${SQLMAP.DSF} in XML to call rights SQL)        record.getsqlmap (). Put ("DSF", Datascopefilter (Record.getcurrentuser (), "O", "a"));         // Set Paging Parameters         record.setpage (page);         // Perform paged queries         page.setlist (recorddao.findlist (record));         return page;    }    

The Get method for the Entity class field you want to export is written with an annotation above it:

@ExcelField (title= "mode", align=2, sort=800, Fieldtype=rolelisttype.  Class)

To export the data of a child table from the main table

Be sure to write out each field of the table in the main table, and generate a Get Set method

Write the upper annotation above the Get method.

Java Excel Export

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.