zoukankan      html  css  js  c++  java
  • 前端JS Excel解析导入

    需要引入:

    <script src="https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.14.0/xlsx.core.min.js"></script>

    html:

    <!DOCTYPE html>
    <html lang="en">
    
    <head>
      <meta charset="UTF-8">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <meta http-equiv="X-UA-Compatible" content="ie=edge">
    </head>
    
    <body>
      <input type="file" onchange="importXlsx(this)">
    </body>

    JS:

      function importXlsx(e) {
        let files = e.files;
        for (let i = 0; i < files.length; i++) {
          let reader = new FileReader();
          let name = files[i].name;
          reader.onload = function (e) {
            let data = e.target.result;
            let workbook = XLSX.read(data, {
              type: typeof FileReader !== "undefined" && (FileReader.prototype || {}).readAsBinaryString ?
                'binary' : 'array'
            });
            let workbookSheets = workbook.Sheets;
            for (let sheet in workbookSheets) {
              if (workbookSheets.hasOwnProperty(sheet)) {
                fromTo = workbookSheets[sheet]['!ref'];
                let xlsxData = XLSX.utils.sheet_to_json(workbookSheets[sheet]);
                // 结果数组
                console.log(sheet)
                console.log(xlsxData);
              }
            }
          };
          reader.readAsBinaryString(files[i]);
        }
      }
  • 相关阅读:
    网络协议 7
    网络协议 6
    PHP 扩展管理
    网络协议 5
    什么是DevOps?
    C# Web API Modify Post Data Size Limit
    Redis 数据变化通知服务实践
    .net 相关性能计数器丢失问题解决方案
    为什么要DevOps?
    分布式服务发现的几种模型
  • 原文地址:https://www.cnblogs.com/xinchenhui/p/9772520.html
Copyright © 2011-2022 走看看