1导入与导出功能实现
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> <input type="button" value="导入" onclick="file_in()"><br><br> <input type="button" value="导出" onclick="file_out()"> <!--导入文件使用控件--> <input type="file" id="excel_in" style="display:none;" /> <!-- 导出文件使用控件,标签不需要内容 --> <a href="javascript" id="excel_out" download="这里是下载的文件名.xlsx" style="display:none;"></a> <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script> <script src="http://oss.sheetjs.com/js-xlsx/xlsx.full.min.js"></script> <script type="text/javascript" src="xlsxhelper.js"></script> <script type="text/javascript"> //导入excel function file_in() { $('#excel_in').click(); } $('#excel_in').change(function (e) { xlsx.importf(this, getexceldata); }) function getexceldata(info) { console.log(info); } var jsono = [{ //测试数据 "保质期临期预警(天)": "adventLifecycle", "商品标题": "title", "建议零售价": "defaultPrice" }, { //测试数据 "保质期临期预警(天)": "adventLifecycle2", "商品标题": "title2", "建议零售价": "defaultPrice2" }]; //导出excel function file_out() { $('#excel_out').attr('download', 'download.xls'); xlsx.downloadExl(jsono, $('#excel_out')[0]); }; </script> </body> </html>