明树Git Lab

Commit 1e68e8c1 authored by zengfanpei's avatar zengfanpei

update

parent b542490c
const ExcelJS = require('exceljs');
const _ = require('lodash');
async function importExcel(req, res, next) {
try {
let workbook = new ExcelJS.Workbook();
console.log(req.file)
await workbook.xlsx.readFile(req.file.path);
let worksheet = workbook.getWorksheet(1);
console.log(worksheet.actualRowCount);
let arr = [];
for (let index = 2; index < worksheet.actualRowCount; index++) {
let values = worksheet.getRow(index).values;
let obj = {
creator: req.user._id,
province: values[1],
city: values[2],
county: values[3],
town: values[4],
zone: values[5],
plantArea:values[6],
varieties: values[7],
area: values[8],
yield: values[9],
yieldValue: values[10],
year: values[11]
}
arr.push(obj)
}
if(arr.length) {
await DB.AreaRecord.insertMany(arr);
}
res.sendData(arr);
} catch (error) {
next(error)
}
}
module.exports = {
importExcel
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment