Home > Web Front-end > JS Tutorial > body text

Nodejs method of reading and writing excel content

小云云
Release: 2018-03-19 09:45:59
Original
2571 people have browsed it

This article mainly introduces the method of nodejs to simply read and write excel content, briefly analyzes the common nodejs reading and writing Excel modules, and analyzes the specific operation skills of nodejs reading and writing Excel in the form of examples. I hope it can help everyone.

Node.js module that supports reading and writing Excel

node-xlsx: Parses excel file data and generates excel files based on Node.js, only supports xlsx format files;
excel-parser: Parses excel file data based on Node.js, supports xls and xlsx format files;
excel-export: Generates and exports data based on Node.js excel file, the generated file format is xlsx;
node-xlrd: Extract data from excel files based on node.js, only supports xls format files.

I will show how to extract the data in the uploaded excel file through node-xlsx and generate a new excel file. The code is as follows:


var xlsx = require('node-xlsx');
var fs = require('fs');
//读取文件内容
var obj = xlsx.parse(__dirname+'/test.xlsx');
var excelObj=obj[0].data;
console.log(excelObj);
var data = [];
for(var i in excelObj){
  var arr=[];
  var value=excelObj[i];
  for(var j in value){
    arr.push(value[j]);
  }
  data.push(arr);
}
var buffer = xlsx.build([
  {
    name:'sheet1',
    data:data
  }
]);
//将文件内容插入新的文件中
fs.writeFileSync('test1.xlsx',buffer,{'flag':'w'});
Copy after login

Related recommendations:

php read and write excel php process Excel Step introduction

PHP reads and writes EXCEL class

php reads and writes excel class, supports multiple workbooks and custom styles

The above is the detailed content of Nodejs method of reading and writing excel content. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!