明树Git Lab
Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
J
jt_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
jt_backend
Commits
34260035
Commit
34260035
authored
Dec 06, 2025
by
zfp1
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
6588ab91
Pipeline
#104237
passed with stage
in 3 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
11 deletions
+28
-11
templateController.js
controller/templateController.js
+28
-11
No files found.
controller/templateController.js
View file @
34260035
...
...
@@ -8,6 +8,7 @@ const ExcelJS = require('exceljs');
const
path
=
require
(
'path'
);
const
{
HyperFormula
}
=
require
(
'hyperformula'
);
const
errorMessage
=
require
(
"../utils/errorMessage"
);
const
_
=
require
(
'lodash'
);
const
keyName
=
{
tjjh
:
"投决计划"
,
...
...
@@ -33,16 +34,31 @@ async function getXmtzzjllTem({ startYear, endYear, tampName, projectId }) {
}
// 2.2 处理数据
let
rows
=
Array
(
worksheet
.
actualRowCount
-
3
).
fill
(
Array
(
columns
.
length
).
fill
(
""
))
;
// 5 是模板有5行
let
rows
=
[]
;
// 5 是模板有5行
if
(
projectId
)
{
let
tzzjlls
=
await
DB
.
ProjectTzzjll
.
findAll
({
where
:
{
projectId
:
projectId
,
del
:
0
},
let
excelData
=
await
DB
.
ProjectExcelData
.
findOne
({
order
:
[[
'createdAt'
,
'DESC'
]],
where
:
{
projectId
:
projectId
,
del
:
0
,
tampName
},
attributes
:
[
'data'
,
'createdAt'
,
'id'
],
raw
:
true
,
});
tzzjlls
=
_
.
sortBy
(
tzzjlls
,
'year'
);
rows
=
thvc
(
tzzjlls
);
console
.
log
(
excelData
.
id
);
if
(
excelData
&&
excelData
.
id
&&
_
.
isArray
(
excelData
.
data
)
&&
excelData
.
data
.
length
>
0
)
{
for
(
let
index
=
3
;
index
<
excelData
.
data
.
length
;
index
++
)
{
// 0、1行是表头
let
element
=
excelData
.
data
[
index
];
if
(
index
)
{
element
=
element
.
slice
(
3
);
}
console
.
log
(
element
)
rows
.
push
(
element
);
}
}
else
{
rows
=
Array
(
worksheet
.
actualRowCount
-
3
).
fill
(
Array
(
columns
.
length
).
fill
(
""
))
}
}
else
{
rows
=
Array
(
worksheet
.
actualRowCount
-
3
).
fill
(
Array
(
columns
.
length
).
fill
(
""
))
}
console
.
log
(
rows
,
"============="
)
//
console.log(rows, "=============")
// 使用addTable创建表格
worksheet
.
addTable
({
...
...
@@ -170,7 +186,7 @@ async function importExcelTempData(req, res, next) {
}
else
if
(
cell
.
type
===
ExcelJS
.
ValueType
.
String
)
{
rowData
.
push
(
cell
.
text
+
"_suffix"
);
}
else
if
(
cell
.
value
===
null
||
cell
.
value
===
undefined
)
{
rowData
.
push
(
null
);
rowData
.
push
(
""
);
}
else
{
rowData
.
push
(
cell
.
value
);
}
...
...
@@ -183,18 +199,19 @@ async function importExcelTempData(req, res, next) {
const
out
=
[];
for
(
let
r
=
0
;
r
<
height
;
r
++
)
{
let
cc
=
[];
for
(
let
c
=
0
;
c
<
sheetData
[
0
].
length
;
c
++
)
{
for
(
let
c
=
0
;
c
<
sheetData
[
0
].
length
;
c
++
)
{
// const formulaString = hf.getCellFormula({ sheet: 0, row: r, col: c });
let
calculated
=
hf
.
getCellValue
({
sheet
:
0
,
row
:
r
,
col
:
c
});
// console.log(formulaString, calculated)
if
(
typeof
calculated
==
'string'
)
{
calculated
=
removeSuffix
(
String
(
calculated
),
'_suffix'
)
if
(
typeof
calculated
==
'string'
)
{
calculated
=
removeSuffix
(
String
(
calculated
),
'_suffix'
)
}
cc
.
push
(
calculated
);
}
out
.
push
(
cc
);
}
await
DB
.
ProjectExcelData
.
create
({
projectId
,
tampName
,
data
:
out
});
await
DB
.
ProjectExcelData
.
create
({
projectId
,
tampName
,
data
:
out
});
req
.
file
=
null
;
return
res
.
sendData
(
out
);
}
catch
(
error
)
{
next
(
error
)
...
...
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