本教程需要安装Phpexcel组件,可以在应用中心下载,需要精通php技术的开发人员使用
一、将数据导出Excel文件
方法引用:
\Phpcmf\Service::L('Phpexcel')->down_excel( $config, $field, $data);
$config 参数配置
$field 字段显示配置
$data 具体数据
示例参考:
$data = [
0 => [ ... ],
1 => [ ... ],
];
$config = [
'author' => '作者', // 作者
'title' => '标题标题', // 标题
'border_color' => '000', // 表格框颜色
'head_bg_color' => 'eef1f5', // 头部背景颜色
'head_font_size' => '12', // 标题字体大小
'head_height' => 40, // 标题高度
];
$field = [
'A' => [
'name' => '范围', // 表格显示名称
'type' => 'text', // 显示方式
'field' => 'pid', // 对应字段名称
'width' => 10, // 宽度
'height' => 80, // 高度
'align' => 'left', // 居左显示,默认居中
'center' => 'true', // 是否居中对齐
],
'B' => [
'name' => '类型',
'type' => 'text',
'field' => 'tid',
'width' => 10,
],
'C' => [
'name' => '卡号',
'type' => 'text',
'field' => 'sn',
'width' => 30,
],
'D' => [
'name' => '密码',
'type' => 'text',
'field' => 'password',
'width' => 20,
],
'E' => [
'name' => '面额',
'type' => 'text',
'field' => 'value',
'width' => 15,
],
'F' => [
'name' => '时间',
'type' => 'text',
'field' => 'inputtime',
'width' => 15,
],
'G' => [
'name' => '二维码',
'type' => 'image', // 作为图片显示
'field' => 'ewm',
'width' => 15,
'image_height' => 60, // 图片高度
'image_x' => 20, // x坐标开始
'image_y' => 20, // y坐标开始
],
];
\Phpcmf\Service::L('Phpexcel')->down_excel( $config, $field, $data);
二、将excel文件导入到数组
$file = "excel文件路径,不是url,是绝对路径";
$data = \Phpcmf\Service::L('Phpexcel')->get_excel($file);
var_dump($data);
打印数组可得到excel格式
导入我建议限制2MB以下的文件,大文件内存占用太大了,会很慢的