當前位置:
首頁 >
前端技术
> javascript
>内容正文
javascript
Node.js实现Excel转JSON
生活随笔
收集整理的這篇文章主要介紹了
Node.js实现Excel转JSON
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
根目錄data文件下inputer文件夾下test.xlsx,輸出文件test.json到outer文件夾下為test.json文件,process.cwd()獲得根目錄 ?、轉為 .json ?.text ?.doc都可以;
方法1: node-xlsx、fs
var xlsx = require("node-xlsx"); var fs = require('fs'); var path = require('path');var list = xlsx.parse(process.cwd() + '/data/inputer/test.xlsx');writeFile(path.join(process.cwd()+'/data/outer',"test.json"),JSON.stringify(list)); function writeFile(fileName,data) {fs.writeFile(fileName,data,'utf-8',complete);function complete(err){if(!err){console.log("文件生成成功");}} }方法2: xls-to-json
var node_xj = require("xls-to-json"); node_xj({input: process.cwd()+"/data/inputer/test.xlsx",output: process.cwd()+"/data/outer/test.json" }, function (err, result) {if (err) {console.error(err);} else {console.log(result);} });?
轉載于:https://www.cnblogs.com/dck1004589696/p/8392233.html
總結
以上是生活随笔為你收集整理的Node.js实现Excel转JSON的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 基础命令(三)
- 下一篇: JSP第四篇【EL表达式介绍、获取各类数