html - trying to download excel file -




this html ajax code....

    <form id="formfilter1" method="get" target="hidden-form">                              select start date:<input type="date" name="start" id="start" required=""/>                              enter end date:<input type="date" name="end" id="end" required=""/>                             <input type="submit" value="submit" />                          </form>                         <iframe style="display:none" name="hidden-form"></iframe>        <script type="text/javascript">                 $("#formfilter1").submit(function (e) {                      e.preventdefault();                     $("#loaderid").show();                     var formdata = $("#formfilter1").serialize();                     console.log(formdata);                      $("#show").load("gettableexportsales?" + formdata, function (responsetxt, statustxt, xhr) {                         console.log("statustxt" + statustxt);                         //                       console.log("responsetxt"+responsetxt);                         //                          console.log("xhr"+xhr);                         if (statustxt === "success")                             $("#loaderid").hide();                         if (statustxt === "error")                             alert("no data found");                     });                  });              </script>   

this controller..

    /*      * change license header, choose license headers in project properties.      * change template file, choose tools | templates      * , open template in editor.      */     package com.admin.dash.core.sales.controller;      import com.admin.dash.core.sales.entity.salesentity;     import com.admin.dash.modules.sale.repository.salesrepository;     import com.admin.dash.modules.sale.service.excelsaleslistreportview;     import java.text.simpledateformat;     import java.util.arraylist;     import java.util.date;     import java.util.hashmap;     import java.util.iterator;     import java.util.list;     import java.util.map;     import javax.servlet.http.httpservletrequest;     import javax.servlet.http.httpservletresponse;     import org.springframework.beans.factory.annotation.autowired;     import org.springframework.stereotype.controller;     import org.springframework.web.bind.annotation.requestmapping;     import org.springframework.web.bind.annotation.requestmethod;     import org.springframework.web.bind.annotation.requestparam;     import org.springframework.web.servlet.modelandview;      /**      *      * @author administrator      */     @controller     public class salesexportcontroller {         @autowired         private salesrepository salesrepository;         @requestmapping(value = "gettableexportsales", method = requestmethod.get)         public modelandview  getsalestableexport(@requestparam("start") string start, @requestparam("end") string end,httpservletrequest request, httpservletresponse response) throws exception {         simpledateformat sdf = new simpledateformat("yyyy-mm-dd");           date d = sdf.parse(start);           date d2 = sdf.parse(end);           system.out.println("starting data :::"+d);            system.out.println("ending  data :::"+d2);             //map<string, object> model = new hashmap<string, object>();             //sheet name            // model.put("sheetname", "testsheetname");             //headers list             /*list<string> headers = new arraylist<string>();             headers.add("column1");             headers.add("column2");             headers.add("column3");*/            list<salesentity> saleslist = new arraylist<>();            list<object[]> listsales = new arraylist<>();            listsales = salesrepository.findallforexport(d, d2);             (iterator<object[]> = listsales.iterator(); it.hasnext();) {                       object[] index = it.next();                       salesentity newsales=new salesentity();                       newsales.setcusfirstname((string) index[37]);                       newsales.setcuslastname((string) index[38]);                       newsales.setphone_no((string) index[39]);                       newsales.setalt_phone_no((string) index[40]);                       newsales.setfirstname((string) index[41]);                       newsales.setlastname((string) index[42]);                       newsales.setid((integer) index[0]);                       newsales.setcreatedat((date) index[1]);                       newsales.setproduct((string) index[2]);                       newsales.setarea((string) index[3]);                       newsales.setsitelocation((string) index[4]);                       newsales.setstate((string) index[5]);                       newsales.setcity((string) index[6]);                       newsales.setkvphp((string) index[7]);                       newsales.setsector((string) index[8]);                       newsales.setsource((string) index[9]);                       newsales.setremark((string) index[10]);                       newsales.setactorprocess((string) index[11]);                       newsales.setpulseid((string) index[12]);                       newsales.setpulsedate((date) index[13]);                       newsales.settypeofcustomer((string) index[14]);                       newsales.setquantity((integer) index[15]);                       newsales.setescalation((string) index[16]);                       newsales.setconversation((string) index[17]);                       newsales.setdealername((string) index[18]);                       newsales.setkoell1((string) index[19]);                       newsales.setkoell2((string) index[20]);                       newsales.setkoell3((string) index[21]);                       newsales.setkoell4((string) index[22]);                       newsales.setsevendaydelivery((string) index[23]);                       newsales.setrecordid((string) index[24]);                       saleslist.add(newsales);                      }             system.out.println("size  java controller "+saleslist.size());           //  model.put("results",saleslist);           //  response.setcontenttype( "application/ms-excel" );           //  response.setheader( "content-disposition", "attachment; filename=myfile.xls" );                      return new modelandview( new excelsaleslistreportview(),"saleslist", saleslist);     }     } 

and class file

    /*      * change license header, choose license headers in project properties.      * change template file, choose tools | templates      * , open template in editor.      */     package com.admin.dash.modules.sale.service;      import com.admin.dash.core.sales.entity.salesentity;     import java.util.list;     import java.util.map;     import javax.servlet.http.httpservletrequest;     import javax.servlet.http.httpservletresponse;     import org.apache.poi.ss.usermodel.row;     import org.apache.poi.ss.usermodel.sheet;     import org.apache.poi.ss.usermodel.workbook;     import org.springframework.stereotype.service;     import org.springframework.web.servlet.view.document.abstractxlsview;      /**      *      * @author administrator      */     @service     public class excelsaleslistreportview extends abstractxlsview{          @override         protected void buildexceldocument(map<string, object> model, workbook workbook, httpservletrequest request, httpservletresponse response) throws exception {             //throw new unsupportedoperationexception("not supported yet."); //to change body of generated methods, choose tools | templates.              response.setheader("content-disposition", "attachment;filename=\"saleslist.xls\"");        @suppresswarnings("unchecked")         list<salesentity> list=(list<salesentity>) model.get("saleslist");         sheet sheet=workbook.createsheet("saleslist");         row header=sheet.createrow(0);         header.createcell(0).setcellvalue("customer first name");         header.createcell(1).setcellvalue("customer last name");         header.createcell(2).setcellvalue("phone no");         header.createcell(3).setcellvalue("alternative phone no ");         int rownum=1;         system.out.println("size excel list java class "+list.size());         for(salesentity salesentity:list){             row row=sheet.createrow(rownum++);             row.createcell(0).setcellvalue(salesentity.getcusfirstname());             row.createcell(1).setcellvalue(salesentity.getcuslastname());             row.createcell(2).setcellvalue(salesentity.getphone_no());             row.createcell(3).setcellvalue(salesentity.getalt_phone_no());            }        // fileoutputstream outputstream = new fileoutputstream("saleslist.xls");               //  workbook.write(outputstream);          }        } 

sorry new on stackoverflow please me, output coming this

��ࡱ�;�� !������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������ ��a����\p administrator b�a=���=h:�#8x@�"��1���arial1���arial1���arial1���arial"$"#,##0_);("$"#,##0)!"$"#,##0_);[red]("$"#,##0)""$"#,##0.00_);("$"#,##0.00)'""$"#,##0.00_);[red]("$"#,##0.00)7*2_("$"*

,##0_);("$"* (#,##0);("$"* "-");(@).))(* #,##0_);(* (#,##0);(* "-");(@)?,:("$"* #,##0.00_);_("$"*

(#,##0.00);_("$"* "-"?? saleslist����customer first namecustomer last namevaibhav singh shahmanojkumarashok pramod...bipin kumaratulsathehirensinh jadeja c.babasaialfredvimaltickoomunnayadhavgurdip singhbalbir inayat pathanrakeshkumar sanjay kumarraiaabhashdeependra singhdipakrameshsirsagarneerajkumar tate paduchandanmehtasartajjirajesh





wiki

Comments

Popular posts from this blog

Asterisk AGI Python Script to Dialplan does not work -

python - Read npy file directly from S3 StreamingBody -

kotlin - Out-projected type in generic interface prohibits the use of metod with generic parameter -