您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

Node解决Excel内容的获取问题

2024/2/18 8:56:53发布25次查看
本文主要给大家介绍了关于利用node解决简单重复问题系列之excel内容获取的相关资料,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习吧。
开整
环境 : node.js
框架 :
 dependencies: {  node-xlsx: ^0.11.2  }
逻辑 :
excel表格样式
期待输出样式
如上两图展示那样,直接取出相应的值拼接成想到的输出格式。
上代码
'use strict' var xlsx = require('node-xlsx'); var fs = require('fs'); var path = require('path') var files = path.resolve(__dirname); var excelpath; fs.readdir(files ,function (error,allfiles){  if(error){  console.log(error);  }else{  allfiles.foreach(function(filename){   var filedir = path.join(files,filename);   fs.stat(filedir,function(error,stats){   if(error){    console.log(error);   }else{    // console.log(filedir);    if (filedir.indexof('xlsx') > 0){    excelpath = filedir;    craeatlanguagetext();    }   }   });  })  } }); function craeatlanguagetext(){  console.log(excelpath);  //读取文件内容  var obj = xlsx.parse(excelpath);  var excelobj = obj[0].data;  var data = [];  var arr = [];// 语言种类  for (var i in excelobj) {  var value = excelobj[i];  for (var j in value) {   if (i == 0) {   if (j > 1) {    arr.push(value[j]);   }   } else {   if (j > 1) {    var str = arr[j - 2];    var item = value[0]    var vaue = value[j];    var reg = /'/    vaue = vaue.replace(reg, ');    str = str + '\n' + '' + item + '' + ' ' + '=' +   + '' + vaue + '' + ';';    arr[j - 2] = str;    console.log(str);   }   }  }  }  var languagestr = arr.join('\n');  //将文件内容插入新的文件中  fs.writefilesync('language.text', languagestr, { encoding: utf8 }); }
逻辑比较容易看懂,不再赘述,直接在node项目文件夹拖入要解析的excel 运行即可。
相关推荐:
利用python将图片转换成excel文档格式详解
node之excel内容的获取
php中通用的excel导出方法实例
以上就是node解决excel内容的获取问题的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product