您当前的位置:首页 > 计算机 > 编程开发 > Html+Div+Css(前端)

前端 ex2json 用于 vue/react/js 将 xls、xlsx、csv 文件转成 json 数组

时间:12-20来源:作者:点击数:
城东书院 www.cdsy.xyz

一、简介

  • 可以在vuereactjs… 等前端开发中,将excelcsv文件转成json对象提交给服务器。
  • 只需要导入文件,即可获得转出的json数组对象,每个sheet一个数组,其次每行一个数组,再其次每个单元格的值存放到行数组中,支持合并的单元格解析。

二、使用

  • 安装
    $ npm i ex2json
    
  • 引入
    import ex2json from "ex2json";
    
  • 使用
    <template>
      <input type="file" @change="read" />
    </template>
    
    <script>
      import ex2json from "ex2json";
      export default {
        methods: {
          read(e) {
            // 文件对象
            const file = e.target.files[0];
            // 转成成 json
            ex2json.parse(file, (code, res) => {
              console.log(code, res);
            });
          },
        },
      };
    </script>
    
城东书院 www.cdsy.xyz
方便获取更多学习、工作、生活信息请关注本站微信公众号城东书院 微信服务号城东书院 微信订阅号
推荐内容
相关内容
栏目更新
栏目热门