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'});
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!