js实现xlsx, xls转json

本文介绍了一种方法,通过前端页面提交数据,然后利用Node.js进行处理,将xlsx和xls文件转换为JSON。数据过滤在HTML页面上完成,而Node.js仅负责写入操作。启动流程包括在根目录运行`node index.js`,默认监听端口8081。主要涉及的文件有index.js和generateJsonFile.js。
摘要由CSDN通过智能技术生成

思路用前端页面提交数据 用node进行写入

数据的过滤逻辑在index.html中完成 node只进行写入操作

文件目录如下

需要现在根目录下启动index.js

node index.js

默认端口号是8081

 

前端页面显示如下

<!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=Chrome">
    <title>Document</title>
    <style>
        img {
            width: 50px;
            height: 50px;
        }

        input[type='file'] {
            display: none;
        }
    </style>
</head>

<body>

    <h2>转换后的文件保存在transform目录中</h2>
    <h4>需要在json()和 xlsx()方法中把data过滤成自己需要的方式</h2>
    <label for="jsonFile">
        editJson <img src="file.gif" alt="">
    </label>
    <input type="file" id="jsonFile" multiple accept="application/json">

    <br>
    <br>
    <label for="xlsxFile">
        xlsxToJson <img src="file.gif" alt="">
    </label>
    <input type="file" id="xlsxFile" multiple accept="application/vnd.ms-excel">
</body>
<script src="shim.min.js"></script>
<script src="xlsx.full.min.js"></script>
<script>
    jsonFile.onchange = jsonFileChanged;
    xlsxFile.onchange = xlsxFileChanged;

    function xlsxFileChanged() {
        if (this.files.length > 0) {
            let fileData = {};
            let reader = fileReader(this.files, readAs = 'readAsBinaryString', fi
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值