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

Nodejs code implementation for reading Excel data and downloading pictures

不言
Release: 2018-08-02 10:30:49
Original
1832 people have browsed it

This article introduces to you how to define global variables and global methods in vue? (code), it has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

Because organizing movie viewing activities requires counting registrations and collecting film reviews, I chose the WeChat applet "Registration Tool". When the administrator downloaded the data, he found that the film review was just a URL link to a picture, and he needed to download it manually. Where can I Stumping programmers?

1. Downloaded Excel data sheet:

Nodejs code implementation for reading Excel data and downloading pictures

2. Code:

const xlsx = require('xlsx');
const mkdirp = require('mkdirp');
const request = require('request');
const fs = require('fs');

const workbook = xlsx.readFile('data.xls');

const sheetNames = workbook.SheetNames; // 返回 ['sheet1', ...]
const worksheet = workbook.Sheets[sheetNames[0]];
const data = xlsx.utils.sheet_to_json(worksheet);

const dir = './images';

// 创建文件夹
mkdirp(dir);

data.forEach(item => {
    request.head(item.img, (err, res, body) => {
        request(item.img).pipe(fs.createWriteStream(dir + "/" + item.name+'.jpg'));
    });
})
Copy after login

3. Running results :

Nodejs code implementation for reading Excel data and downloading pictures

Related recommendations:

A brief discussion on high concurrency and distributed clusters in node.js

Parsing of encapsulation in JS object-oriented programming

The above is the detailed content of Nodejs code implementation for reading Excel data and downloading pictures. 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!