明树Git Lab
Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
L
letian_backend
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
zengfanpei
letian_backend
Commits
1e68e8c1
Commit
1e68e8c1
authored
Oct 18, 2024
by
zengfanpei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
b542490c
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
60 additions
and
0 deletions
+60
-0
areaRecordController.js
controller/areaRecordController.js
+60
-0
No files found.
controller/areaRecordController.js
0 → 100644
View file @
1e68e8c1
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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment