English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
以下是一个示例:
<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": [ ,1标题" {"value":"B"1标题" ], "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) { //Primero convertir json var arrData = typeof JSONData != 'object' ? JSON.parse(JSONData) : JSONData; var excel = '<table>'; //Establecer encabezado var row = "<tr>"; for (var i = 0, l = ShowLabel.length; i < l; i++) { row += "<td>" + ShowLabel[i].value + '</td>'; } //Salto de línea excel += row + "</tr>"; //Establecer datos 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="Exportar" /> </body> </html>
La manera de descargar un array JSON en formato Excel como tabla en este artículo de JavaScript que he compartido con todos es todo el contenido que he compartido, espero que les sirva de referencia y que apoyen y griten más教程.
Declaración: El contenido de este artículo se ha obtenido de la red, es propiedad del autor original, el contenido se ha contribuido y subido por los usuarios de Internet de manera autónoma, este sitio no posee los derechos de propiedad, no se ha realizado un procesamiento editorial humano y no asume responsabilidades legales relacionadas. Si encuentra contenido sospechoso de infracción de derechos de autor, por favor envíe un correo electrónico a: notice#oldtoolbag.com (al enviar un correo electrónico, reemplace # con @ para denunciar y proporcione evidencia relevante. Una vez verificada, este sitio eliminará inmediatamente el contenido sospechoso de infracción de derechos de autor.)