In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article introduces you how to analyze excel in nodejs, the content is very detailed, interested friends can refer to, hope to be helpful to you.
First, use this package to read an excel file. The excel file is as follows:
The content is simple. It's just a table.
If we use node-xlsx, we have to install it and introduce it. Node-xlsx is introduced into the file to receive it with a custom variable, which has two methods, parse and build.
Parse means parsing excel. Let's first look at the code for parsing the above table with nodejs to get the data:
Var xlsx = require ('node-xlsx'). Default
/ / the parameter of the parse method is the path of the excel to be parsed
Var list = xlsx.parse ('. / 1234.xlsx')
/ / output data
Console.log (list)
The print result is as follows:
We see that the result is an array, each item in the array is an object, and the object has the following properties: name, data.
Name is the name of the document in excel. Note here that an excel can have multiple documents as shown in the figure:
So the list above gets an array.
Data represents the data under the current document, which is a two-dimensional array, which we output:
You can see that the data is the same as in the table above. It's just that the format of this data is special, usually the first behavior header row, followed by the behavior entity data, and stored as an array.
It should be noted that if some data in the table in excel is empty, it is not filled in as shown in the figure:
The data read out at this time is as follows:
Convert to json as follows:
This npm package is quite user-friendly, and the above is to use nodejs to read excel files.
Let's take a look at how to write data to excel with nodejs, and to write data to excel with nodejs, the data must meet the requirements, and the fs module of nodejs is needed here.
The code is as follows:
The running result is output to the test4.xlsx file as follows:
As you can see from the above running results, when building the written data, the data must be set to an array, and the empty item must be set to null, then build a buffer data according to the interface of node-xlsx, and finally output the buffer data to the page.
To expand, let's take a look at the following table:
With a merged header, how to output such data? The code is as follows:
On how to parse excel in nodejs to share here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.