Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

juncode/excel

Open more actions menu
 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Excel 处理

安装

composer require pfinal/excel

使用示例

导入Excel

<?php

include 'vendor/autoload.php';

use PFinal\Excel\Excel;

date_default_timezone_set('PRC');

$data = Excel::readExcelFile('./1.xlsx', ['id' => '编号', 'name' => '姓名', 'date' => '日期']);

//处理日期
array_walk($data, function (&$item) {
    $item['date'] = Excel::convertTime($item['date'], 'Y-m-d');
});

var_dump($data);

//如果数据量大,建议用csv格式
$data = Excel::readExcelFile('./1.csv', ['id' => '编号', 'name' => '姓名', 'date' => '日期'], 1, 1, '', 'GBK');

Excel中的数据:

得到结果如下:

$data = [
    ['id'=>1,'name'=>'张三', 'date'=>'2017-07-18'],
    ['id'=>1,'name'=>'李四', 'date'=>'2017-07-19'],
    ['id'=>1,'name'=>'王五', 'date'=>'2017-07-20'],
];

导出到Excel文件

$data = array(
    array('id' => 1, 'name' => 'Jack', 'age' => 18, 'date'=>'2017-07-18']),
    array('id' => 2, 'name' => 'Mary', 'age' => 20, 'date'=>'2017-07-18']),
    array('id' => 3, 'name' => 'Ethan', 'age' => 34, 'date'=>'2017-07-18']),
);

$map = array(
    'title'=>[
        'id' => '编号',
        'name' => '姓名',
        'age' => '年龄',
     ],
);

$file = 'user' . date('Y-m-d');

Excel::exportExcel($data, $map, $file, '用户信息');



About

PHP中导入导出Excel文件,导出支持100K+ row

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%
Morty Proxy This is a proxified and sanitized view of the page, visit original site.