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>
html页

相关文章:

  • 2022-01-24
  • 2021-11-21
  • 2021-08-29
  • 2023-01-04
  • 2022-12-23
  • 2021-11-18
  • 2021-11-04
  • 2021-06-04
猜你喜欢
  • 2021-12-11
  • 2021-09-18
  • 2021-08-30
  • 2022-12-23
  • 2021-10-02
  • 2021-12-22
相关资源
相似解决方案