function btn_exportexecl () { $ .ajax ({ type: "GET", // GET or POST url: "/ the Export / ExportExceldc", // the request url Address Data: {holeid: ID}, // request parameter dataType : "JSON" , Success: function (jsonData) { // loop through each row was added tr tag, each tag cell plus td the let STR = '<Table border = ". 1">' + '<tr> <td colspan = 4 align = "center" > demonstrates the execl <TD> </ TR> '+ ' <TR> '+ ' <TD> value 1 </ td> <td> '+ jsonData [1] [' value 1 ' ] + '</ TD>' + '<TD> value 2 </ td> <td> '+ JsonData [1] [ 'value 2'] + '</ TD>' + '</ TR>' + '<TR>' + '<TD> Numerical 3 </ td> <td> ' + jsonData [1 ] [ 'number 5'] + '</ td >' + '<TD> Numerical 4 </ td> <td> ' + jsonData [1 ] [ 'number 6'] + '</ td >' + '</ TR>' + '<TR>' + '<TD> Column 1 </ td> <td> Column 2 </ TD>' + '<TD> Column 3 </ td> <td> Column 4 < / TD> '+ ' </ TR> ' ; ; for (the let I = 0; I <jsonData.length; I ++ ) { STR + =' <TR> ' ; // increase \ t in order to prevent the count table shows SCIENCES method or other format str + = `<td> $ {jsonData [i] [ ' columns. 1'] + '\ T'} </ TD>`; str + = `<td> $ {jsonData [i] [ ' column 2 '] +' \ T '} </ TD> `; STR + =` <TD> $ {jsonData [I] [' columns. 3 '] +' \ T '} </ TD> `; STR + = `<td> $ {jsonData [ i] [ ' column. 4'] + '\ T'} </ TD>`; STR + = '</ TR>' ; } str += '</table>'; //Worksheet名 let uri let worksheet = 'sheet1'= 'data:application/vnd.ms-excel;base64,'; //下载的表格模板数据 let template = `<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40"> <head><!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet> <x:Name>${worksheet}</x:Name> <x:WorksheetOptions><x:DisplayGridlines/></x:WorksheetOptions></x:ExcelWorksheet> </x:ExcelWorksheets></x:ExcelWorkbook></xml><![endif]--> </head><body><table>${str}</table></ body> </ HTML> </ TT> `; varwindow.location.href URI + = Base64 (Template) //download templates// = document.createElement Link ( "A" ); link.href = URI + Base64 (Template) link.download = 'test' ; // the name of the execl link.target = '_blank' ; document.body.appendChild (Link) ; link.click (); document.body.removeChild (Link); }, error: function () { // function failed } })
Export execl file is this ..........