Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
jamesyang1999
ShopXO
提交
9241b1bc
ShopXO
项目概览
jamesyang1999
/
ShopXO
与 Fork 源项目一致
Fork自
纵之格 / ShopXO
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
ShopXO
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
9241b1bc
编写于
9月 30, 2019
作者:
D
devil_gong
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
excel导出优化
上级
d184a4de
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
82 addition
and
24 deletion
+82
-24
application/admin/controller/Order.php
application/admin/controller/Order.php
+1
-1
application/admin/controller/User.php
application/admin/controller/User.php
+1
-1
extend/base/Excel.php
extend/base/Excel.php
+80
-22
未找到文件。
application/admin/controller/Order.php
浏览文件 @
9241b1bc
...
@@ -139,7 +139,7 @@ class Order extends Common
...
@@ -139,7 +139,7 @@ class Order extends Common
$data_params
=
array
(
$data_params
=
array
(
'where'
=>
$where
,
'where'
=>
$where
,
'm'
=>
0
,
'm'
=>
0
,
'n'
=>
10000
0
,
'n'
=>
0
,
'is_excel_export'
=>
1
,
'is_excel_export'
=>
1
,
);
);
$data
=
OrderService
::
OrderList
(
$data_params
);
$data
=
OrderService
::
OrderList
(
$data_params
);
...
...
application/admin/controller/User.php
浏览文件 @
9241b1bc
...
@@ -109,7 +109,7 @@ class User extends Common
...
@@ -109,7 +109,7 @@ class User extends Common
$data_params
=
[
$data_params
=
[
'where'
=>
$where
,
'where'
=>
$where
,
'm'
=>
0
,
'm'
=>
0
,
'n'
=>
10000
0
,
'n'
=>
0
,
];
];
$data
=
UserService
::
UserList
(
$data_params
);
$data
=
UserService
::
UserList
(
$data_params
);
...
...
extend/base/Excel.php
浏览文件 @
9241b1bc
...
@@ -24,9 +24,11 @@ class Excel
...
@@ -24,9 +24,11 @@ class Excel
private
$suffix
;
private
$suffix
;
private
$data
;
private
$data
;
private
$title
;
private
$title
;
private
$string
;
private
$jump_url
;
private
$jump_url
;
private
$msg
;
private
$msg
;
private
$horizontal_center
;
private
$vertical_center
;
private
$warap_text
;
/**
/**
* [__construct 构造方法]
* [__construct 构造方法]
...
@@ -34,38 +36,48 @@ class Excel
...
@@ -34,38 +36,48 @@ class Excel
* @blog http://gong.gg/
* @blog http://gong.gg/
* @version 0.0.1
* @version 0.0.1
* @datetime 2017-01-10T15:09:17+0800
* @datetime 2017-01-10T15:09:17+0800
* @param [string] $param['filename'] [文件名称(追加当前时间)]
* @param [string] $params['filename'] [文件名称(追加当前时间)]
* @param [string] $param['suffix'] [文件后缀名(默认xls)]
* @param [string] $params['suffix'] [文件后缀名(默认xls)]
* @param [string] $param['jump_url'] [出错跳转url地址(默认上一个页面)]
* @param [string] $params['jump_url'] [出错跳转url地址(默认上一个页面)]
* @param [string] $param['msg'] [错误提示信息]
* @param [string] $params['msg'] [错误提示信息]
* @param [string] $param['file_type'] [导出文件类型(默认excel)]
* @param [string] $params['file_type'] [导出文件类型(默认excel)]
* @param [array] $param['title'] [标题(二维数组)]
* @param [array] $params['title'] [标题(二维数组)]
* @param [array] $param['data'] [数据(二维数组)]
* @param [array] $params['data'] [数据(二维数组)]
* @param [int] $params['horizontal_center'] [是否水平居中 1是]
* @param [int] $params['vertical_center'] [是否垂直居中 1是]
* @param [int] $params['warap_text'] [是否内容自动换行 1是]
*/
*/
public
function
__construct
(
$param
=
array
()
)
public
function
__construct
(
$param
s
=
[]
)
{
{
// 文件名称
// 文件名称
$date
=
date
(
'YmdHis'
);
$date
=
date
(
'YmdHis'
);
$this
->
filename
=
isset
(
$param
[
'filename'
])
?
$param
[
'filename'
]
.
'-'
.
$date
:
$date
;
$this
->
filename
=
isset
(
$param
s
[
'filename'
])
?
$params
[
'filename'
]
.
'-'
.
$date
:
$date
;
// 文件类型, 默认excel
// 文件类型, 默认excel
$type_all
=
array
(
'excel'
=>
'vnd.ms-excel'
,
'pdf'
=>
'pdf'
);
$type_all
=
array
(
'excel'
=>
'vnd.ms-excel'
,
'pdf'
=>
'pdf'
);
$this
->
file_type
=
(
isset
(
$param
[
'file_type'
])
&&
isset
(
$type_all
[
$param
[
'file_type'
]]))
?
$type_all
[
$param
[
'file_type'
]]
:
$type_all
[
'excel'
];
$this
->
file_type
=
(
isset
(
$param
s
[
'file_type'
])
&&
isset
(
$type_all
[
$params
[
'file_type'
]]))
?
$type_all
[
$params
[
'file_type'
]]
:
$type_all
[
'excel'
];
// 文件后缀名称
// 文件后缀名称
$this
->
suffix
=
empty
(
$param
[
'suffix'
])
?
'xls'
:
$param
[
'suffix'
];
$this
->
suffix
=
empty
(
$param
s
[
'suffix'
])
?
'xls'
:
$params
[
'suffix'
];
// 标题
// 标题
$this
->
title
=
isset
(
$param
[
'title'
])
?
$param
[
'title'
]
:
array
()
;
$this
->
title
=
isset
(
$param
s
[
'title'
])
?
$params
[
'title'
]
:
[]
;
// 数据
// 数据
$this
->
data
=
isset
(
$param
[
'data'
])
?
$param
[
'data'
]
:
array
()
;
$this
->
data
=
isset
(
$param
s
[
'data'
])
?
$params
[
'data'
]
:
[]
;
// 出错跳转地址
// 出错跳转地址
$this
->
jump_url
=
empty
(
$param
[
'jump_url'
])
?
$_SERVER
[
'HTTP_REFERER'
]
:
$param
[
'jump_url'
];
$this
->
jump_url
=
empty
(
$param
s
[
'jump_url'
])
?
$_SERVER
[
'HTTP_REFERER'
]
:
$params
[
'jump_url'
];
// 错误提示信息
// 错误提示信息
$this
->
msg
=
empty
(
$param
[
'msg'
])
?
'title or data cannot be empty!'
:
$param
[
'msg'
];
$this
->
msg
=
empty
(
$params
[
'msg'
])
?
'title or data cannot be empty!'
:
$params
[
'msg'
];
// 水平,垂直居中
$this
->
horizontal_center
=
isset
(
$params
[
'horizontal_center'
])
?
intval
(
$params
[
'horizontal_center'
])
:
1
;
$this
->
vertical_center
=
isset
(
$params
[
'vertical_center'
])
?
intval
(
$params
[
'vertical_center'
])
:
1
;
// 内容自动换行
$this
->
warap_text
=
isset
(
$params
[
'warap_text'
])
?
intval
(
$params
[
'warap_text'
])
:
1
;
// 引入PHPExcel类库
// 引入PHPExcel类库
require
ROOT
.
'extend'
.
DS
.
'phpexcel'
.
DS
.
'PHPExcel.php'
;
require
ROOT
.
'extend'
.
DS
.
'phpexcel'
.
DS
.
'PHPExcel.php'
;
...
@@ -112,12 +124,28 @@ class Excel
...
@@ -112,12 +124,28 @@ class Excel
$excel_charset
=
MyC
(
'admin_excel_charset'
,
0
);
$excel_charset
=
MyC
(
'admin_excel_charset'
,
0
);
$charset
=
lang
(
'common_excel_charset_list'
)[
$excel_charset
][
'value'
];
$charset
=
lang
(
'common_excel_charset_list'
)[
$excel_charset
][
'value'
];
// 水平,垂直居中
if
(
$this
->
horizontal_center
==
1
)
{
$excel
->
getActiveSheet
()
->
getDefaultStyle
()
->
getAlignment
()
->
setHorizontal
(
\
PHPExcel_Style_Alignment
::
HORIZONTAL_CENTER
);
}
if
(
$this
->
vertical_center
==
1
)
{
$excel
->
getActiveSheet
()
->
getDefaultStyle
()
->
getAlignment
()
->
setVertical
(
\
PHPExcel_Style_Alignment
::
VERTICAL_CENTER
);
}
//设置自动换行
if
(
$this
->
warap_text
==
1
)
{
$excel
->
getActiveSheet
()
->
getDefaultStyle
()
->
getAlignment
()
->
setWrapText
(
true
);
}
// 标题
// 标题
$temp_key
=
0
;
$temp_key
=
0
;
foreach
(
$this
->
title
as
$k
=>
$v
)
foreach
(
$this
->
title
as
$k
=>
$v
)
{
{
$col
=
\
PHPExcel_Cell
::
stringFromColumnIndex
(
$temp_key
);
$col
=
\
PHPExcel_Cell
::
stringFromColumnIndex
(
$temp_key
)
.
'1'
;
$excel
->
getActiveSheet
()
->
setCellValue
(
$col
.
'1'
,
(
$excel_charset
==
0
)
?
$v
[
'name'
]
:
iconv
(
'utf-8'
,
$charset
,
$v
[
'name'
]));
$excel
->
getActiveSheet
()
->
setCellValue
(
$col
,
(
$excel_charset
==
0
)
?
$v
[
'name'
]
:
iconv
(
'utf-8'
,
$charset
,
$v
[
'name'
]));
$temp_key
++
;
$temp_key
++
;
}
}
...
@@ -130,8 +158,38 @@ class Excel
...
@@ -130,8 +158,38 @@ class Excel
$temp_key
=
0
;
$temp_key
=
0
;
foreach
(
$this
->
title
as
$tk
=>
$tv
)
foreach
(
$this
->
title
as
$tk
=>
$tv
)
{
{
$height
=
isset
(
$tv
[
'height'
])
?
intval
(
$tv
[
'height'
])
:
0
;
$width
=
isset
(
$tv
[
'width'
])
?
intval
(
$tv
[
'width'
])
:
$height
;
$col
=
\
PHPExcel_Cell
::
stringFromColumnIndex
(
$temp_key
);
$col
=
\
PHPExcel_Cell
::
stringFromColumnIndex
(
$temp_key
);
$excel
->
getActiveSheet
()
->
setCellValueExplicit
(
$col
.
$i
,
(
$excel_charset
==
0
)
?
$v
[
$tk
]
:
iconv
(
'utf-8'
,
$charset
,
$v
[
$tk
]),
\
PHPExcel_Cell_DataType
::
TYPE_STRING
);
if
(
$tv
[
'type'
]
==
'images'
)
{
$drawing
=
new
\
PHPExcel_Worksheet_Drawing
();
$drawing
->
setPath
(
$v
[
$tk
]);
// 设置宽度高度
$number
=
empty
(
$height
)
?
50
:
$height
-
10
;
$drawing
->
setHeight
(
$number
);
$drawing
->
setWidth
(
$number
);
$drawing
->
setCoordinates
(
$col
.
$i
);
// 图片偏移距离
$x
=
(
$width
>
0
)
?
((
$width
-
$number
)
/
2
)
+
15
:
15
;
$drawing
->
setOffsetX
(
$x
);
$drawing
->
setOffsetY
(
15
);
$drawing
->
setWorksheet
(
$excel
->
getActiveSheet
());
}
else
{
$excel
->
getActiveSheet
()
->
setCellValueExplicit
(
$col
.
$i
,
(
$excel_charset
==
0
)
?
$v
[
$tk
]
:
iconv
(
'utf-8'
,
$charset
,
$v
[
$tk
]),
\
PHPExcel_Cell_DataType
::
TYPE_STRING
);
}
// 单元格宽高
if
(
$width
>
0
)
{
$excel
->
getActiveSheet
()
->
getColumnDimension
(
$col
)
->
setWidth
(
$width
/
5
);
}
if
(
$height
>
0
)
{
$excel
->
getActiveSheet
()
->
getRowDimension
(
$i
)
->
setRowHeight
(
$height
);
}
$temp_key
++
;
$temp_key
++
;
}
}
}
}
...
@@ -192,14 +250,14 @@ class Excel
...
@@ -192,14 +250,14 @@ class Excel
$highest_column_index
=
\
PHPExcel_Cell
::
columnIndexFromString
(
$highest_column
);
$highest_column_index
=
\
PHPExcel_Cell
::
columnIndexFromString
(
$highest_column
);
// 定义变量
// 定义变量
$result
=
array
()
;
$result
=
[]
;
$field
=
array
()
;
$field
=
[]
;
// 读取数据
// 读取数据
for
(
$row
=
1
;
$row
<=
$highest_row
;
$row
++
)
for
(
$row
=
1
;
$row
<=
$highest_row
;
$row
++
)
{
{
// 临时数据
// 临时数据
$info
=
array
()
;
$info
=
[]
;
// 注意 highest_column_index 的列数索引从0开始
// 注意 highest_column_index 的列数索引从0开始
for
(
$col
=
0
;
$col
<
$highest_column_index
;
$col
++
)
for
(
$col
=
0
;
$col
<
$highest_column_index
;
$col
++
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录