https://github.com/dashingunique/excel
Excel import/export for Php
https://github.com/dashingunique/excel
Last synced: about 2 months ago
JSON representation
Excel import/export for Php
- Host: GitHub
- URL: https://github.com/dashingunique/excel
- Owner: dashingunique
- License: mit
- Created: 2020-06-23T03:16:38.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2020-07-08T08:16:50.000Z (almost 6 years ago)
- Last Synced: 2025-12-14T09:19:24.738Z (6 months ago)
- Language: PHP
- Size: 10.7 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# excel
Excel import/export for Php
Install via composer:
```
composer require dashingUnique/excel
```
## 导出文件信息
将文件导出到 `.csv`(.xlsx .obs) 文件:
```php
use dashingUnique\excel\DashingExcel;
use app\model\User;
// Load users
$users = new User()->select();
$users = uniqueCollection($users);
// Export all users
(new DashingExcel($users))->export('file.csv');
```
仅导入指定信息的列
```php
$users = new User()->select();
$users = uniqueCollection($users);
(new DashingExcel($users))->export('users.csv', function ($user) {
return [
'Email' => $user['email'],
'First Name' => $user['firstname'],
'Last Name' => strtotime($user['create_time']),
];
});
```
## 导入文件信息
导入文件信息
```php
$collection = (new DashingExcel())->configureCsv(';', '#', '\n', 'gbk')->import('file.csv');
```
导入文件并写入数据库
```php
$users = (new DashingExcel())->import('file.xlsx', function ($line) {
return (new User())->create([
'name' => $line['Name'],
'email' => $line['Email']
]);
});
```