English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
Example as follows:
<html> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8"> <script type="text/javascript" src="jquery183.min.js"></script> <script type="text/javascript"> $(document).ready(function(){ $('#wwo').click(function(){ var data = { "title": [ {"value":"A"1Title"}, {"value":"B"1Title"} ], "data": [ [ {"value":"好好"}, {"value":"2015-08-24"} ], [ {"value":"123}, {"value":"hahah"} ] ] }; if(data == ''){ return; }else{ JSONToExcelConvertor(data.data, "Report", data.title); } }); }); function JSONToExcelConvertor(JSONData, FileName, ShowLabel) { //First convert json var arrData = typeof JSONData != 'object' ? JSON.parse(JSONData) : JSONData; var excel = '<table>'; //Set table header var row = "<tr>"; for (var i = 0, l = ShowLabel.length; i < l; i++) { row += "<td>" + ShowLabel[i].value + </td>'; } //New line excel += row + "</tr>"; //Set data for (var i = 0; i < arrData.length; i++) { var row = "<tr>"; for (var index in arrData[i]) { var value = arrData[i][index].value === "." ? "" : arrData[i][index].value; row += '<td>' + value + </td>'; } excel += row + "</tr>"; } excel += excel;/table>"; var excelFile = "<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'>"; = "<body>"; += '<meta http-equiv="content-type" content="application/= "<-excel; charset=UTF-8">'; = "<body>"; += '<meta http-equiv="content-type" content="application/= "<-excel'; = "<body>"; += '; charset=UTF-8">'; = "<body>"; += "<head>"; = "<body>"; += "<!--[if gte mso 9]>"; = "<body>"; += "<xml>"; = "<body>"; += "<x:ExcelWorkbook>"; = "<body>"; += "<x:ExcelWorksheets>"; = "<body>"; += "<x:ExcelWorksheet>"; = "<body>"; += "<x:Name>"; = "<body>"; += "{worksheet}"; = "<body>"; += excel;/x:Name>"; = "<body>"; += "<x:WorksheetOptions>"; = "<body>"; += "<x:DisplayGridlines/x:ExcelWorkbook>"; = "<body>"; += excel;/x:WorksheetOptions>"; = "<body>"; += excel;/x:ExcelWorksheet>"; = "<body>"; += excel;/x:ExcelWorksheets>"; = "<body>"; += excel;/x:ExcelWorkbook>"; = "<body>"; += excel;/xml>"; = "<body>"; +x:ExcelWorksheets>";--x:ExcelWorkbook>"; = "<body>"; += excel;/xml>"; = "<body>"; += "<![endif]", = "<body>"; +>"; = "<body>"; += excel;/head>"; = "<body>"; += excel;/body>"; excelFile/= "<-html>";-8, + var uri = 'data:application vnd.ms excel;charset=utf , link.download = FileName + ".xls"; document.body.appendChild(link); link.click(); document.body.removeChild(link); } </script> </head> <body> <input type="button" id="wwo" value="Export"> /> </body> </html>
This method of converting a JSON format array to an Excel table in JavaScript, which is shared by the editor, is all the content I have to share with everyone. I hope it can be a reference for everyone, and I also hope everyone will support and cheer for the tutorial.
Statement: The content of this article is from the network, and the copyright belongs to the original author. The content is contributed and uploaded by Internet users spontaneously. This website does not own the copyright, does not undergo manual editing, and does not assume relevant legal liabilities. If you find any content suspected of copyright infringement, please send an email to: notice#w3Please report to codebox.com (replace # with @ when sending an email) and provide relevant evidence. Once verified, this site will immediately delete the infringing content.