Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
data-collect-api
Overview
Overview
Details
Activity
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
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wenyi.chen
data-collect-api
Commits
49dff0f9
Commit
49dff0f9
authored
Apr 02, 2024
by
wenyi.chen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
线上更新
parent
97ec0eba
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
378 additions
and
83 deletions
+378
-83
app/api/controller/ExcelFile.php
+369
-74
app/api/controller/Test.php
+1
-4
app/api/route/api.php
+6
-4
config/config.php
+2
-1
public/import.xlsx
+0
-0
No files found.
app/api/controller/ExcelFile.php
View file @
49dff0f9
...
@@ -135,26 +135,185 @@ class ExcelFile extends BaseController
...
@@ -135,26 +135,185 @@ class ExcelFile extends BaseController
/**
/**
* @return void
* @return void
*
导出任务
*
按任务导出文件
*/
*/
public
function
taskExportFile
()
public
function
taskExportFile
()
{
{
try
{
try
{
$task
=
Db
::
table
(
'task_package'
)
->
where
(
'id'
,
22
)
->
find
();
$id
=
input
(
"param.id"
,
0
,
"intval"
);
$norm
=
Db
::
table
(
'norm'
)
->
where
(
'task_id'
,
22
)
->
select
();
if
(
empty
(
$id
)){
$list
=
[];
return
returnResult
(
config
(
"config.code.error"
),
'ID错误!'
,[]);
foreach
(
$norm
as
$value
){
}
$sheet
=
[
'total'
=>
0
,
'data'
=>
[]];
$task
=
Db
::
table
(
'task_package'
)
->
where
(
'id'
,
$id
)
->
find
();
$normList
=
Db
::
table
(
'norm_list'
)
->
where
(
'norm_id'
,
$value
[
'id'
])
->
select
();
if
(
$task
){
$longest
=
0
;
$norm
=
Db
::
table
(
'norm'
)
->
where
(
'task_id'
,
$task
[
'id'
])
->
select
();
$total
=
0
;
if
(
$norm
){
$list
=
[];
foreach
(
$norm
as
$value
){
$sheet
=
[
'title'
=>
$value
[
'name'
],
'data'
=>
[]];
$normList
=
Db
::
table
(
'norm_list'
)
->
where
(
'norm_id'
,
$value
[
'id'
])
->
select
();
foreach
(
$normList
as
$index
=>
$val
){
$normReceives
=
Db
::
table
(
'norm_receives'
)
->
where
(
'norm_list_id'
,
$val
[
'id'
])
->
find
();
$normCollects
=
Db
::
table
(
'norm_collects'
)
->
where
(
'norm_list_id'
,
$val
[
'id'
])
->
find
();
$referType
=
'/'
;
// 信源类型
$imgPath
=
'/'
;
// 图片
$remark
=
'/'
;
$normCollectsId
=
''
;
$not_collectible
=
'/'
;
$not_collectible_remarks
=
'/'
;
$reviewStatus
=
'/'
;
// 填写内容
if
(
$normCollects
){
if
(
$normCollects
[
'refer_type'
]
==
1
){
$referType
=
'官网/政府'
;
}
else
if
(
$normCollects
[
'refer_type'
]
==
2
){
$referType
=
'权威媒体'
;
}
else
{
$referType
=
'其他可信信源'
;
}
if
(
$normCollects
[
'imgPath'
]){
$imgPath
=
$normCollects
[
'imgPath'
];
}
if
(
$normCollects
[
'remark'
]){
$remark
=
$normCollects
[
'remark'
];
}
$normCollectsId
=
$normCollects
[
'id'
];
}
// 是否可以采集
if
(
$normReceives
){
if
(
$normReceives
[
'not_collectible'
]
==
1
){
$not_collectible
=
'不可采集'
;
$not_collectible_remarks
=
$normReceives
[
'not_collectible_remarks'
];
}
else
{
$not_collectible
=
'可采集'
;
}
if
(
$normReceives
[
'status'
]
==
0
){
$reviewStatus
=
'已领取、未完成'
;
}
else
if
(
$normReceives
[
'status'
]
==
1
){
$reviewStatus
=
'已完成、未审核'
;
}
else
if
(
$normReceives
[
'status'
]
==
2
){
$reviewStatus
=
'审核不通过'
;
}
else
if
(
$normReceives
[
'status'
]
==
3
){
$reviewStatus
=
'审核通过'
;
}
else
if
(
$normReceives
[
'status'
]
==
4
){
$reviewStatus
=
'已经结算'
;
}
else
{
$reviewStatus
=
'/'
;
}
}
// 难度等级
if
(
isset
(
$val
[
'level'
])){
$val
[
'level'
]
=
$val
[
'level'
]
.
'级'
;
}
else
{
$val
[
'level'
]
=
'/'
;
}
if
(
isset
(
$val
[
'sort'
])){
if
(
$val
[
'sort'
]
==
1
){
$val
[
'sort'
]
=
'低'
;
}
else
if
(
$val
[
'sort'
]
==
2
){
$val
[
'sort'
]
=
'中'
;
}
else
{
$val
[
'sort'
]
=
'高'
;
}
}
else
{
$val
[
'sort'
]
=
'/'
;
}
$data
=
[
'name'
=>
$val
[
'name'
],
'level'
=>
$val
[
'level'
],
'refer'
=>
$val
[
'refer'
],
'price'
=>
$val
[
'price'
],
'guide'
=>
$value
[
'guide'
],
'sort'
=>
$val
[
'sort'
],
'remark'
=>
$remark
,
'referType'
=>
$referType
,
'admin'
=>
[],
'user'
=>
[],
'adminLength'
=>
0
,
'userLength'
=>
0
,
'imgPath'
=>
$imgPath
,
'not_collectible'
=>
$not_collectible
,
'not_collectible_remarks'
=>
$not_collectible_remarks
,
'review_status'
=>
$reviewStatus
,
];
$normListExtend
=
Db
::
table
(
'norm_list_extend'
)
->
where
(
'norm_list_id'
,
$val
[
'id'
])
->
select
();
// 添加展示端
foreach
(
$normListExtend
as
$extendValue
){
$arr
=
[
'name'
=>
$extendValue
[
'extend_name'
],
'value'
=>
$extendValue
[
'extend_value'
]];
array_push
(
$data
[
'admin'
],
$arr
);
}
// 添加用户端
if
(
$normCollectsId
){
$collectsInfo
=
Db
::
table
(
'norm_collects_extend'
)
->
where
(
'norm_collects_id'
,
$normCollectsId
)
->
select
();
foreach
(
$collectsInfo
as
$collectsValue
){
$arr
=
[
'name'
=>
$collectsValue
[
'extend_name'
],
'value'
=>
$collectsValue
[
'extend_value'
]];
array_push
(
$data
[
'user'
],
$arr
);
}
}
// 添加第一条指标信息
array_push
(
$sheet
[
'data'
],
$data
);
}
if
(
$sheet
[
'data'
]){
array_push
(
$list
,
$sheet
);
}
}
// 创建一个新的 Spreadsheet 对象
$spreadsheet
=
new
Spreadsheet
();
// 设置为活动工作表
$spreadsheet
->
createSheet
();
for
(
$i
=
0
;
$i
<
count
(
$list
);
$i
++
){
$this
->
exportFile
(
$spreadsheet
,
$i
,
$list
[
$i
][
'title'
],
$list
[
$i
][
'data'
]);
}
// 保存 ExcelFile 文件
$writer
=
new
Xlsx
(
$spreadsheet
);
$name
=
'xlsx/'
.
$task
[
'name'
]
.
'_'
.
date
(
'YmdHis'
)
.
'.xlsx'
;
$writer
->
save
(
$name
);
// header('Content-Type: application/vnd.ms-excel');
// header('Content-Disposition: attachment;filename="'.$task['name'].'_'.date('YmdHis').'.xlsx"');
// header('Cache-Control: max-age=0');
// // 输出Excel文件到浏览器
// $writer->save('php://output');
return
returnResult
(
config
(
"config.code.success"
),
config
(
"config.describe.success"
),
config
(
"config.resource_address"
)
.
'public/'
.
$name
);
}
else
{
return
returnResult
(
config
(
"config.code.success"
),
'该任务下未找到相关指标信息!'
,[]);
}
}
else
{
return
returnResult
(
config
(
"config.code.error"
),
'没有该任务存在!'
,[]);
}
}
catch
(
\Exception
$e
){
var_dump
(
$e
->
getMessage
());
}
}
/**
* @return void
* 按指标导出文件
*/
public
function
normExportFile
()
{
try
{
$id
=
input
(
"param.id"
,
0
,
"intval"
);
if
(
empty
(
$id
)){
return
returnResult
(
config
(
"config.code.error"
),
'ID错误!'
,[]);
}
$norm
=
Db
::
table
(
'norm'
)
->
where
(
'id'
,
$id
)
->
find
();
if
(
$norm
){
$list
=
[];
$sheet
=
[
'title'
=>
$norm
[
'name'
],
'data'
=>
[]];
$normList
=
Db
::
table
(
'norm_list'
)
->
where
(
'norm_id'
,
$norm
[
'id'
])
->
select
();
foreach
(
$normList
as
$index
=>
$val
){
foreach
(
$normList
as
$index
=>
$val
){
$
total
=
0
;
$
normReceives
=
Db
::
table
(
'norm_receives'
)
->
where
(
'norm_list_id'
,
$val
[
'id'
])
->
find
()
;
$normCollects
=
Db
::
table
(
'norm_collects'
)
->
where
(
'norm_list_id'
,
$val
[
'id'
])
->
find
();
$normCollects
=
Db
::
table
(
'norm_collects'
)
->
where
(
'norm_list_id'
,
$val
[
'id'
])
->
find
();
$referType
=
'
无
'
;
// 信源类型
$referType
=
'
/
'
;
// 信源类型
$imgPath
=
'
无
'
;
// 图片
$imgPath
=
'
/
'
;
// 图片
$remark
=
'
无
'
;
$remark
=
'
/
'
;
$normCollectsId
=
''
;
$normCollectsId
=
''
;
$not_collectible
=
'/'
;
$not_collectible_remarks
=
'/'
;
$reviewStatus
=
'/'
;
// 填写内容
if
(
$normCollects
){
if
(
$normCollects
){
if
(
$normCollects
[
'refer_type'
]
==
1
){
if
(
$normCollects
[
'refer_type'
]
==
1
){
$referType
=
'官网/政府'
;
$referType
=
'官网/政府'
;
...
@@ -171,24 +330,66 @@ class ExcelFile extends BaseController
...
@@ -171,24 +330,66 @@ class ExcelFile extends BaseController
}
}
$normCollectsId
=
$normCollects
[
'id'
];
$normCollectsId
=
$normCollects
[
'id'
];
}
}
// 是否可以采集
if
(
$normReceives
){
if
(
$normReceives
[
'not_collectible'
]
==
1
){
$not_collectible
=
'不可采集'
;
$not_collectible_remarks
=
$normReceives
[
'not_collectible_remarks'
];
}
else
{
$not_collectible
=
'可采集'
;
}
if
(
$normReceives
[
'status'
]
==
0
){
$reviewStatus
=
'已领取、未完成'
;
}
else
if
(
$normReceives
[
'status'
]
==
1
){
$reviewStatus
=
'已完成、未审核'
;
}
else
if
(
$normReceives
[
'status'
]
==
2
){
$reviewStatus
=
'审核不通过'
;
}
else
if
(
$normReceives
[
'status'
]
==
3
){
$reviewStatus
=
'审核通过'
;
}
else
if
(
$normReceives
[
'status'
]
==
4
){
$reviewStatus
=
'已经结算'
;
}
else
{
$reviewStatus
=
'/'
;
}
}
// 难度等级
if
(
isset
(
$val
[
'level'
])){
$val
[
'level'
]
=
$val
[
'level'
]
.
'级'
;
}
else
{
$val
[
'level'
]
=
'/'
;
}
if
(
isset
(
$val
[
'sort'
])){
if
(
$val
[
'sort'
]
==
1
){
$val
[
'sort'
]
=
'低'
;
}
else
if
(
$val
[
'sort'
]
==
2
){
$val
[
'sort'
]
=
'中'
;
}
else
{
$val
[
'sort'
]
=
'高'
;
}
}
else
{
$val
[
'sort'
]
=
'/'
;
}
$data
=
[
$data
=
[
'number'
=>
$index
,
'name'
=>
$val
[
'name'
],
'name'
=>
$val
[
'name'
],
'level'
=>
$val
[
'level'
],
'level'
=>
$val
[
'level'
],
'refer'
=>
$val
[
'refer'
],
'refer'
=>
$val
[
'refer'
],
'price'
=>
$val
[
'price'
],
'price'
=>
$val
[
'price'
],
'guide'
=>
$
value
[
'guide'
],
'guide'
=>
$
norm
[
'guide'
],
'sort'
=>
$val
ue
[
'sort'
],
'sort'
=>
$val
[
'sort'
],
'remark'
=>
$remark
,
'remark'
=>
$remark
,
'referType'
=>
$referType
,
'referType'
=>
$referType
,
'admin'
=>
[],
'admin'
=>
[],
'user'
=>
[],
'user'
=>
[],
'imgPath'
=>
$imgPath
'adminLength'
=>
0
,
'userLength'
=>
0
,
'imgPath'
=>
$imgPath
,
'not_collectible'
=>
$not_collectible
,
'not_collectible_remarks'
=>
$not_collectible_remarks
,
'review_status'
=>
$reviewStatus
,
];
];
$normListExtend
=
Db
::
table
(
'norm_list_extend'
)
->
where
(
'norm_list_id'
,
$val
[
'id'
])
->
select
();
$normListExtend
=
Db
::
table
(
'norm_list_extend'
)
->
where
(
'norm_list_id'
,
$val
[
'id'
])
->
select
();
// 添加展示端
// 添加展示端
foreach
(
$normListExtend
as
$extendValue
){
foreach
(
$normListExtend
as
$extendValue
){
$total
+=
1
;
$arr
=
[
'name'
=>
$extendValue
[
'extend_name'
],
'value'
=>
$extendValue
[
'extend_value'
]];
$arr
=
[
'name'
=>
$extendValue
[
'extend_name'
],
'value'
=>
$extendValue
[
'extend_value'
]];
array_push
(
$data
[
'admin'
],
$arr
);
array_push
(
$data
[
'admin'
],
$arr
);
}
}
...
@@ -196,37 +397,61 @@ class ExcelFile extends BaseController
...
@@ -196,37 +397,61 @@ class ExcelFile extends BaseController
if
(
$normCollectsId
){
if
(
$normCollectsId
){
$collectsInfo
=
Db
::
table
(
'norm_collects_extend'
)
->
where
(
'norm_collects_id'
,
$normCollectsId
)
->
select
();
$collectsInfo
=
Db
::
table
(
'norm_collects_extend'
)
->
where
(
'norm_collects_id'
,
$normCollectsId
)
->
select
();
foreach
(
$collectsInfo
as
$collectsValue
){
foreach
(
$collectsInfo
as
$collectsValue
){
$total
+=
1
;
$arr
=
[
'name'
=>
$collectsValue
[
'extend_name'
],
'value'
=>
$collectsValue
[
'extend_value'
]];
$arr
=
[
'name'
=>
$collectsValue
[
'extend_name'
],
'value'
=>
$collectsValue
[
'extend_value'
]];
array_push
(
$data
[
'user'
],
$arr
);
array_push
(
$data
[
'user'
],
$arr
);
}
}
}
}
// 添加图片信息
array_push
(
$data
,
$imgPath
);
// 记录表头自定义个数
if
(
$total
>
$longest
){
$longest
=
$total
;
}
$sheet
[
'total'
]
=
$longest
;
// 添加第一条指标信息
// 添加第一条指标信息
array_push
(
$sheet
[
'data'
],
$data
);
array_push
(
$sheet
[
'data'
],
$data
);
}
}
array_push
(
$list
,
$sheet
);
if
(
$sheet
[
'data'
]){
array_push
(
$list
,
$sheet
);
}
// 创建一个新的 Spreadsheet 对象
$spreadsheet
=
new
Spreadsheet
();
// 设置为活动工作表
$spreadsheet
->
createSheet
();
for
(
$i
=
0
;
$i
<
count
(
$list
);
$i
++
){
$this
->
exportFile
(
$spreadsheet
,
$i
,
$list
[
$i
][
'title'
],
$list
[
$i
][
'data'
]);
}
// 保存 ExcelFile 文件
$writer
=
new
Xlsx
(
$spreadsheet
);
$name
=
'xlsx/'
.
$norm
[
'name'
]
.
'_'
.
date
(
'YmdHis'
)
.
'.xlsx'
;
$writer
->
save
(
$name
);
return
returnResult
(
config
(
"config.code.success"
),
config
(
"config.describe.success"
),
config
(
"config.resource_address"
)
.
'public/'
.
$name
);
}
else
{
return
returnResult
(
config
(
"config.code.success"
),
'该任务下未找到相关指标信息!'
,[]);
}
}
$this
->
exportFile
(
$list
[
1
]);
}
catch
(
\Exception
$e
){
}
catch
(
\Exception
$e
){
var_dump
(
$e
->
getMessage
());
var_dump
(
$e
->
getMessage
());
}
}
}
}
public
function
exportFile
(
$data
)
/**
* 单页表格输出
* @param $spreadsheet
* @param $number
* @param $title
* @param $data
* @return void
*/
public
function
exportFile
(
$spreadsheet
,
$number
,
$title
,
$data
)
{
{
try
{
try
{
// 创建一个新的 Spreadsheet 对象
$spreadsheet
->
setActiveSheetIndex
(
$number
);
$spreadsheet
=
new
Spreadsheet
();
$spreadsheet
->
getActiveSheet
(
$number
)
->
setTitle
(
$title
);
$sheet
=
$spreadsheet
->
getActiveSheet
();
$sheet
=
$spreadsheet
->
getActiveSheet
(
$number
);
// 设置A列的所有单元格文本居中
$spreadsheet
->
getDefaultStyle
()
->
getAlignment
()
->
setVertical
(
\PhpOffice\PhpSpreadsheet\Style\Alignment
::
VERTICAL_CENTER
);
$spreadsheet
->
getDefaultStyle
()
->
getAlignment
()
->
setHorizontal
(
\PhpOffice\PhpSpreadsheet\Style\Alignment
::
HORIZONTAL_CENTER
);
$spreadsheet
->
getDefaultStyle
()
->
getAlignment
()
->
setWrapText
(
true
);
$sheet
->
getDefaultRowDimension
()
->
setRowHeight
(
20
);
// 默认行高
$sheet
->
getDefaultColumnDimension
()
->
setWidth
(
20
);
// 默认单元格宽度
$sheet
->
getStyle
(
'A1:Z1'
)
->
getFill
()
->
setFillType
(
\PhpOffice\PhpSpreadsheet\Style\Fill
::
FILL_SOLID
)
->
getStartColor
()
->
setARGB
(
'C5D9F1'
);
// FF后面的六位数是颜色的RGB值
$title
=
[
$title
=
[
'序号'
,
'指标名称'
,
'指标名称'
,
'难度等级'
,
'难度等级'
,
'参考信源'
,
'参考信源'
,
...
@@ -237,7 +462,7 @@ class ExcelFile extends BaseController
...
@@ -237,7 +462,7 @@ class ExcelFile extends BaseController
'信源类型'
,
'信源类型'
,
];
];
$arr
=
[];
$arr
=
[];
foreach
(
$data
[
'data'
]
as
$index
=>
$value
)
{
foreach
(
$data
as
$index
=>
$value
)
{
foreach
(
$value
[
'admin'
]
as
$inx
=>
$val
){
foreach
(
$value
[
'admin'
]
as
$inx
=>
$val
){
if
(
!
in_array
(
$val
[
'name'
],
$arr
)){
if
(
!
in_array
(
$val
[
'name'
],
$arr
)){
array_push
(
$arr
,
$val
[
'name'
]);
array_push
(
$arr
,
$val
[
'name'
]);
...
@@ -250,60 +475,130 @@ class ExcelFile extends BaseController
...
@@ -250,60 +475,130 @@ class ExcelFile extends BaseController
}
}
}
}
$title
=
array_merge
(
$title
,
$arr
);
$title
=
array_merge
(
$title
,
$arr
);
$column
=
[
'A'
,
'B'
,
'C'
,
'D'
,
'E'
.
'F'
,
'G'
,
'H'
,
'I'
,
'J'
,
'K'
,
'L'
,
'M'
,
'N'
,
'O'
,
'P'
,
'Q'
,
'R'
,
'S'
,
'T'
,
'U'
,
'V'
,
'W'
,
'X'
,
'Y'
,
'Z'
];
array_push
(
$title
,
'图片'
);
array_push
(
$title
,
'是否可采集'
);
array_push
(
$title
,
'不可采集原因'
);
array_push
(
$title
,
'审核状态'
);
$column
=
[
'A'
,
'B'
,
'C'
,
'D'
,
'E'
,
'F'
,
'G'
,
'H'
,
'I'
,
'J'
,
'K'
,
'L'
,
'M'
,
'N'
,
'O'
,
'P'
,
'Q'
,
'R'
,
'S'
,
'T'
,
'U'
,
'V'
,
'W'
,
'X'
,
'Y'
,
'Z'
];
$row
=
1
;
$row
=
1
;
// 遍历标题数组,设置每个单元格的值
// 遍历标题数组,设置每个单元格的值
foreach
(
$title
as
$columns
=>
$val
)
{
foreach
(
$title
as
$columns
=>
$val
)
{
// 使用列的数字来定位列,例如 'A', 'B', 'C', ...
// 使用列的数字来定位列,例如 'A', 'B', 'C', ...
$columnLetter
=
chr
(
65
+
$columns
);
$columnLetter
=
chr
(
65
+
$columns
);
$cell
=
$columnLetter
.
$row
;
$cell
=
$columnLetter
.
$row
;
// 设置单元格的值
// 设置单元格的值
$sheet
->
setCellValue
(
$cell
,
$val
);
$sheet
->
setCellValue
(
$cell
,
$val
);
// 设置单元格A1的对齐方式为居中
}
}
$num
=
0
;
$num
=
0
;
$row
=
2
;
$row
=
2
;
foreach
(
$data
[
'data'
]
as
$index
=>
$value
)
{
foreach
(
$data
as
$value
)
{
$position
=
0
;
$sheet
=
$spreadsheet
->
getActiveSheet
();
$sheet
=
$spreadsheet
->
getActiveSheet
();
$sheet
->
setCellValue
(
$column
[
$num
]
.
$row
,
isset
(
$value
[
'number'
])
?
$value
[
'number'
]
:
'无'
);
// 指标名称
// 设置一些数据到单元格中
$sheet
->
setCellValue
(
$column
[
$num
+
$position
]
.
$row
,
$value
[
'name'
]);
$sheet
->
setCellValue
(
$column
[
$num
+
1
]
.
$row
,
isset
(
$value
[
'name'
])
?
$value
[
'name'
]
:
'无'
);
$position
++
;
$sheet
->
setCellValue
(
$column
[
$num
+
2
]
.
$row
,
isset
(
$value
[
'level'
])
?
$value
[
'level'
]
:
'无'
);
// 难度等级
// $sheet->setCellValue($column[$num+2].$index, isset($value['refer'])?$value['refer']:'无');
$sheet
->
setCellValue
(
$column
[
$num
+
$position
]
.
$row
,
$value
[
'level'
]);
// $sheet->setCellValue($column[$num+3].$index, isset($value['price'])?$value['price']:'无');
$position
++
;
// $sheet->setCellValue($column[$num+4].$index, isset($value['guide'])?$value['guide']:'无');
//参考信源
// $sheet->setCellValue($column[$num+5].$index, isset($value['sort'])?$value['sort']:'无');
$sheet
->
setCellValue
(
$column
[
$num
+
$position
]
.
$row
,
$value
[
'refer'
]);
// $sheet->setCellValue($column[$num+6].$index, isset($value['remark'])?$value['remark']:'无');
$position
++
;
// $sheet->setCellValue($column[$num+7].$index, isset($value['referType'])?$value['referType']:'无');
//单价
// $sheet->setCellValue('K'.$index, $value[10]);
$sheet
->
setCellValue
(
$column
[
$num
+
$position
]
.
$row
,
$value
[
'price'
]);
// $sheet->setCellValue('L'.$index,$value[11]);
$position
++
;
// $sheet->setCellValue('M'.$index, $value[12]);
//参考指南
// $sheet->setCellValue('N'.$index, $value[13]);
$sheet
->
setCellValue
(
$column
[
$num
+
$position
]
.
$row
,
$value
[
'guide'
]);
// $sheet->getRowDimension(0)->setRowHeight(50); // 设置第一行的高度为30
$position
++
;
//// $sheet->getRowDimension(1)->setWidth(130); // 设置第一行的高度为30
//优先级
// $sheet->getColumnDimension('A')->setWidth(25); // 设置A列的宽度为20
$sheet
->
setCellValue
(
$column
[
$num
+
$position
]
.
$row
,
$value
[
'sort'
]);
// $sheet->getRowDimension($index+1)->setRowHeight(50); // 设置第一行的高度为30
$position
++
;
//// $sheet->getRowDimension(1)->setWidth(130); // 设置第一行的高度为30
// 备注
// $sheet->getColumnDimension('B')->setWidth(25); // 设置A列的宽度为20
$sheet
->
setCellValue
(
$column
[
$num
+
$position
]
.
$row
,
$value
[
'remark'
]);
// if($value[13] != "无"){
$position
++
;
// var_dump($value[14]);
//信源类型
// // 创建一个 Drawing 对象,并设置图片的路径
$sheet
->
setCellValue
(
$column
[
$num
+
$position
]
.
$row
,
$value
[
'referType'
]);
// $drawing = new Drawing();
$position
++
;
// $drawing->setName('Sample Image');
// $drawing->setDescription('Sample Image');
// 展示端
// $drawing->setPath($value[13]); // 图片路径
foreach
(
$value
[
'admin'
]
as
$ss
){
// $drawing->setCoordinates('N'.$index); // 图片放置的单元格位置
if
(
$ss
[
'name'
]
==
'年份'
){
// $drawing->setWorksheet($sheet); // 关联到工作表
$sheet
->
setCellValue
(
$column
[
$num
+
$position
]
.
$row
,
$ss
[
'value'
]
.
'年'
);
// // 调整图片大小以适应单元格(可选)
}
else
{
// $drawing->setHeight(80); // 图片高度,单位为磅
$sheet
->
setCellValue
(
$column
[
$num
+
$position
]
.
$row
,
$ss
[
'value'
]);
// $drawing->setWidth(80); // 图片宽度,单位为磅
}
// }
$position
++
;
}
// 用户端
foreach
(
$value
[
'user'
]
as
$hh
){
$sheet
->
setCellValue
(
$column
[
$num
+
$position
]
.
$row
,
$hh
[
'value'
]);
$position
++
;
}
$sheet
->
getRowDimension
(
$row
)
->
setRowHeight
(
80
);
// 设置第n行的高度为30
$sheet
->
getColumnDimension
(
$column
[
$num
+
$position
])
->
setWidth
(
30
);
// 设置A列的宽度为20
if
(
$title
[
$position
]
==
'图片'
){
if
(
$value
[
'imgPath'
]
!=
"无"
){
// 创建一个 Drawing 对象,并设置图片的路径
$drawing
=
new
Drawing
();
$drawing
->
setName
(
'Sample Image'
);
$drawing
->
setDescription
(
'Sample Image'
);
$drawing
->
setPath
(
'./storage/topic/20240402/bff4607948a621271fac9b86ca8dc17c.png'
);
// 图片路径
$drawing
->
setCoordinates
(
$column
[
$num
+
$position
]
.
$row
);
// 图片放置的单元格位置
$drawing
->
setWorksheet
(
$sheet
);
// 关联到工作表
// 调整图片大小以适应单元格(可选)
$drawing
->
setHeight
(
136
);
// 图片高度,单位为磅
$drawing
->
setWidth
(
132
);
// 图片宽度,单位为磅
}
else
{
//图片
$sheet
->
setCellValue
(
$column
[
$num
+
$position
]
.
$row
,
'无'
);
$position
++
;
}
}
else
{
while
(
$title
[
$position
]
!=
'图片'
){
$sheet
->
setCellValue
(
$column
[
$num
+
$position
]
.
$row
,
'/'
);
$position
++
;
}
if
(
$value
[
'imgPath'
]
!=
"无"
){
// 创建一个 Drawing 对象,并设置图片的路径
$drawing
=
new
Drawing
();
$drawing
->
setName
(
'Sample Image'
);
$drawing
->
setDescription
(
'Sample Image'
);
$drawing
->
setPath
(
'./storage/topic/20240402/bff4607948a621271fac9b86ca8dc17c.png'
);
// 图片路径
$drawing
->
setCoordinates
(
$column
[
$num
+
$position
]
.
$row
);
// 图片放置的单元格位置
$drawing
->
setWorksheet
(
$sheet
);
// 关联到工作表
// 调整图片大小以适应单元格(可选)
$drawing
->
setHeight
(
136
);
// 图片高度,单位为磅
$drawing
->
setWidth
(
132
);
// 图片宽度,单位为磅
}
else
{
//图片
$sheet
->
setCellValue
(
$column
[
$num
+
$position
]
.
$row
,
'无'
);
$position
++
;
}
}
if
(
$title
[
$position
]
==
'是否可采集'
){
//是否可采集
$sheet
->
setCellValue
(
$column
[
$num
+
$position
]
.
$row
,
$value
[
'not_collectible'
]);
$position
++
;
}
else
{
while
(
$title
[
$position
]
!=
'是否可采集'
){
$sheet
->
setCellValue
(
$column
[
$num
+
$position
]
.
$row
,
'/'
);
$position
++
;
}
//是否可采集
$sheet
->
setCellValue
(
$column
[
$num
+
$position
]
.
$row
,
$value
[
'not_collectible'
]);
$position
++
;
}
//不可采集的原因
$sheet
->
setCellValue
(
$column
[
$num
+
$position
]
.
$row
,
$value
[
'not_collectible_remarks'
]);
$position
++
;
//审核状态
$sheet
->
setCellValue
(
$column
[
$num
+
$position
]
.
$row
,
$value
[
'review_status'
]);
$position
++
;
// 每行++
$row
++
;
$row
++
;
}
}
// 保存 ExcelFile 文件
$writer
=
new
Xlsx
(
$spreadsheet
);
$writer
->
save
(
'import.xlsx'
);
}
catch
(
\Exception
$e
){
}
catch
(
\Exception
$e
){
var_dump
(
$e
->
getMessage
()
);
exception
(
$e
,
'ExcelFile.exportFile'
);
}
}
}
}
...
...
app/api/controller/Test.php
View file @
49dff0f9
...
@@ -25,14 +25,12 @@ class Test extends BaseController
...
@@ -25,14 +25,12 @@ class Test extends BaseController
$spreadsheet
=
new
Spreadsheet
();
$spreadsheet
=
new
Spreadsheet
();
$sheet
=
$spreadsheet
->
getActiveSheet
();
$sheet
=
$spreadsheet
->
getActiveSheet
();
// 设置一些数据到单元格中
$sheet
->
setCellValue
(
'A1'
,
'带有图片的 ExcelFile 表格'
);
// 创建一个 Drawing 对象,并设置图片的路径
// 创建一个 Drawing 对象,并设置图片的路径
$drawing
=
new
Drawing
();
$drawing
=
new
Drawing
();
$drawing
->
setName
(
'Sample Image'
);
$drawing
->
setName
(
'Sample Image'
);
$drawing
->
setDescription
(
'Sample Image'
);
$drawing
->
setDescription
(
'Sample Image'
);
$drawing
->
setPath
(
'./image_0.
pn
g'
);
// 图片路径
$drawing
->
setPath
(
'./image_0.
jp
g'
);
// 图片路径
$drawing
->
setCoordinates
(
'B1'
);
// 图片放置的单元格位置
$drawing
->
setCoordinates
(
'B1'
);
// 图片放置的单元格位置
$drawing
->
setWorksheet
(
$sheet
);
// 关联到工作表
$drawing
->
setWorksheet
(
$sheet
);
// 关联到工作表
...
@@ -84,7 +82,6 @@ class Test extends BaseController
...
@@ -84,7 +82,6 @@ class Test extends BaseController
// 保存Excel文件
// 保存Excel文件
$writer
->
save
(
$outputFileName
);
$writer
->
save
(
$outputFileName
);
// 下载Excel文件(或者你可以返回文件路径让用户自己下载)
// 下载Excel文件(或者你可以返回文件路径让用户自己下载)
// return response()->download($outputFileName, 'file.xlsx')->deleteFileAfterSend(true);
// return response()->download($outputFileName, 'file.xlsx')->deleteFileAfterSend(true);
}
catch
(
\Exception
$e
){
}
catch
(
\Exception
$e
){
...
...
app/api/route/api.php
View file @
49dff0f9
...
@@ -93,9 +93,10 @@ Route::rule("normOrders/list","NormOrders/list"); //结算指标列表
...
@@ -93,9 +93,10 @@ Route::rule("normOrders/list","NormOrders/list"); //结算指标列表
Route
::
rule
(
"normOrders/detail"
,
"NormOrders/detail"
);
//结算指标列表
Route
::
rule
(
"normOrders/detail"
,
"NormOrders/detail"
);
//结算指标列表
Route
::
rule
(
"importFile"
,
"ExcelFile/importFile"
);
//结算指标列表
//
Route::rule("importFile","ExcelFile/importFile"); //结算指标列表
Route
::
rule
(
"exportFile"
,
"ExcelFile/exportFile"
);
//结算指标列表
//
Route::rule("exportFile","ExcelFile/exportFile"); //结算指标列表
Route
::
rule
(
"taskExportFile"
,
"ExcelFile/taskExportFile"
);
//
结算指标列表
Route
::
rule
(
"taskExportFile"
,
"ExcelFile/taskExportFile"
);
//
按任务导出数据
Route
::
rule
(
"normExportFile"
,
"ExcelFile/normExportFile"
);
//按指标导出数据
Route
::
rule
(
"test"
,
"test/index"
);
//结算指标列表
//
Route
::
rule
(
"import"
,
"ImportFile/import"
);
//
Route
::
rule
(
"import"
,
"ImportFile/import"
);
\ No newline at end of file
config/config.php
View file @
49dff0f9
...
@@ -69,5 +69,6 @@ return [
...
@@ -69,5 +69,6 @@ return [
"table_delete"
=>
99
,
// 删除
"table_delete"
=>
99
,
// 删除
],
],
// "resource_address"=>'https://data-collect.raisound.com/data-collect-api/',
// "resource_address"=>'https://data-collect.raisound.com/data-collect-api/',
"resource_address"
=>
'http://192.168.10.168/data-collect-api/'
// "resource_address"=>'http://192.168.10.168/data-collect-api/'
"resource_address"
=>
'http://gcspider.raisound.com:81/data-collect-api/'
];
];
public/import.xlsx
View file @
49dff0f9
No preview for this file type
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