H5纯前端生成Excel表格方法如下:

 1 <!DOCTYPE html>
 2 <html>
 3 <head>
 4     <title></title>
 5     <meta charset="utf-8">
 6     <meta http-equiv="x-ua-compatible">
 7 </head>
 8 <body>
 9 </body>
10 <script src="alasql.js"></script>
11 <script src="xlsx.core.min.js"></script>
12 <script>
13     var arr = [
14       {
15         "姓名":"喵喵喵",
16         "年龄":1,
17       },
18       {
19         "姓名":"喵喵",
20         "年龄":2,
21       }
22     ];
23     alasql('SELECT * INTO XLS("报表.xls",{headers:true}) FROM ?',[arr]);
24 </script>
25 </html>

该html文件引入了两个js文件,这两个文件的内容过长,我把它放到了github上:

alasql.js的地址为https://github.com/LuoYiHao/generate-excel/blob/master/alasql.js

xlsx.core.min.js的地址为:https://github.com/LuoYiHao/generate-excel/blob/master/xlsx.core.min.js

点击运行页面,即可生成excel表格并下载,效果如下:

01-05 10:02