{"id":15025511,"url":"https://github.com/jqhph/easy-excel","last_synced_at":"2025-04-04T16:15:07.134Z","repository":{"id":35402424,"uuid":"215738797","full_name":"jqhph/easy-excel","owner":"jqhph","description":"🚀 快速读写Excel文件，简单高效","archived":false,"fork":false,"pushed_at":"2023-12-27T16:52:58.000Z","size":1718,"stargazers_count":153,"open_issues_count":18,"forks_count":28,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-10-30T05:58:01.225Z","etag":null,"topics":["csv","dcat","excel","laravel-excel","ods","php71","spout","spreadsheet","xlsx"],"latest_commit_sha":null,"homepage":"https://jqhph.github.io/easy-excel","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jqhph.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2019-10-17T08:14:49.000Z","updated_at":"2024-09-25T07:46:59.000Z","dependencies_parsed_at":"2024-01-19T00:03:53.399Z","dependency_job_id":"4f38d702-89c3-4eda-b58e-41a69166c58b","html_url":"https://github.com/jqhph/easy-excel","commit_stats":{"total_commits":72,"total_committers":5,"mean_commits":14.4,"dds":0.08333333333333337,"last_synced_commit":"20ee838b07f1f5d9c075b84e6f4807cbb21c44b0"},"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jqhph%2Feasy-excel","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jqhph%2Feasy-excel/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jqhph%2Feasy-excel/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jqhph%2Feasy-excel/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jqhph","download_url":"https://codeload.github.com/jqhph/easy-excel/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246711536,"owners_count":20821567,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["csv","dcat","excel","laravel-excel","ods","php71","spout","spreadsheet","xlsx"],"created_at":"2024-09-24T20:02:29.143Z","updated_at":"2025-04-04T16:15:07.110Z","avatar_url":"https://github.com/jqhph.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n\n# EASY EXCEL\n\n\u003cp\u003e\n    \u003ca href=\"https://github.com/jqhph/easy-excel/blob/master/LICENSE\"\u003e\u003cimg src=\"https://img.shields.io/badge/license-MIT-7389D8.svg?style=flat\" \u003e\u003c/a\u003e\n     \u003ca href=\"https://styleci.io/repos/215738797\"\u003e\n        \u003cimg src=\"https://github.styleci.io/repos/215738797/shield\" alt=\"StyleCI\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://github.com/jqhph/easy-excel/releases\" \u003e\u003cimg src=\"https://img.shields.io/github/release/jqhph/easy-excel.svg?color=4099DE\" /\u003e\u003c/a\u003e \n    \u003ca href=\"https://packagist.org/packages/dcat/easy-excel\"\u003e\u003cimg src=\"https://img.shields.io/packagist/dt/dcat/easy-excel.svg?color=\" /\u003e\u003c/a\u003e \n    \u003ca\u003e\u003cimg src=\"https://img.shields.io/badge/php-7.1+-59a9f8.svg?style=flat\" /\u003e\u003c/a\u003e \n\u003c/p\u003e\n\n\u003c/div\u003e\n\n`Easy Excel`是一个基于 \u003ca href=\"https://github.com/box/spout\" target=\"_blank\"\u003ebox/spout\u003c/a\u003e 封装的Excel读写工具，可以帮助开发者更快速更轻松地读写Excel文件，\n并且无论读取多大的文件只需占用极少的内存。\n\n\u003e 由于`box/spout`只支持读写`xlsx`、`csv`、`ods`等类型文件，所以本项目目前也仅支持读写这三种类型的文件。\n\n\n## 文档\n\n[文档](https://jqhph.github.io/easy-excel/)\n\n## 环境\n\n- PHP \u003e= 7.1\n- PHP extension php_zip\n- PHP extension php_xmlreader\n- box/spout \u003e= 3.0\n- league/flysystem \u003e= 1.0\n\n\n## 安装\n\n```bash\ncomposer require dcat/easy-excel\n```\n\n### 快速开始\n\n#### 导出\n\n\n下载\n```php\nuse Dcat\\EasyExcel\\Excel;\n\n$array = [\n    ['id' =\u003e 1, 'name' =\u003e 'Brakus', 'email' =\u003e 'treutel@eg.com', 'created_at' =\u003e '...'], \n    ...\n];\n\n$headings = ['id' =\u003e 'ID', 'name' =\u003e '名称', 'email' =\u003e '邮箱'];\n\n// xlsx\nExcel::export($array)-\u003eheadings($headings)-\u003edownload('users.xlsx');\n\n// csv\nExcel::export($array)-\u003eheadings($headings)-\u003edownload('users.csv');\n\n// ods\nExcel::export($array)-\u003eheadings($headings)-\u003edownload('users.ods');\n```\n\n保存\n```php\nuse Dcat\\EasyExcel\\Excel;\nuse League\\Flysystem\\Adapter\\Local;\nuse League\\Flysystem\\Filesystem;\n\n$array = [...];\n\n// 保存到当前服务器\nExcel::export($array)-\u003estore('/tmp/users.xlsx');\n\n\n// 使用 filesystem\n$adapter = new Local(__DIR__);\n\n$filesystem = new Filesystem($adapter);\n\nExcel::export($array)-\u003edisk($filesystem)-\u003estore('users.xlsx');\n```\n\n获取文件内容\n```php\nuse Dcat\\EasyExcel\\Excel;\n\n$array = [...];\n\n$xlsxContents = Excel::xlsx($array)-\u003eraw();\n\n$csvContents = Excel::csv($array)-\u003eraw();\n\n$odsContents = Excel::ods($array)-\u003eraw();\n```\n更多导出功能请参考[文档](https://jqhph.github.io/easy-excel/docs/master/export.html)。\n\n#### 导入\n\n\n读取所有表格数据\n```php\nuse Dcat\\EasyExcel\\Excel;\nuse League\\Flysystem\\Adapter\\Local;\nuse League\\Flysystem\\Filesystem;\n\n$headings = ['id', 'name', 'email'];\n\n// 导入xlsx\n$allSheets = Excel::import('/tmp/users.xlsx')-\u003eheadings($headings)-\u003etoArray();\n\n\n// 使用filesystem\n$adapter = new Local(__DIR__);\n\n$filesystem = new Filesystem($adapter);\n\n$allSheets = Excel::import('users.xlsx')-\u003edisk($filesystem)-\u003eheadings($headings)-\u003etoArray();\n\n\nprint_r($allSheets); // ['Sheet1' =\u003e [['id' =\u003e 1, 'name' =\u003e 'Brakus', 'email' =\u003e 'treutel@eg.com', 'created_at' =\u003e '...']]]\n```\n\n遍历表格\n```php\nuse Dcat\\EasyExcel\\Excel;\nuse Dcat\\EasyExcel\\Contracts\\Sheet as SheetInterface;\nuse Dcat\\EasyExcel\\Support\\SheetCollection;\n\n// 导入xlsx\nExcel::import('/tmp/users.xlsx')-\u003eeach(function (SheetInterface $sheet) {\n    // 获取表格名称，如果是csv文件，则此方法返回空字符串\n    $sheetName = $sheet-\u003egetName();\n\n    // 表格序号，从 0 开始\n    $sheetIndex = $sheet-\u003egetIndex();\n    \n    // 是否是最后一次保存前打开的表格\n    $isActive = $sheet-\u003eisActive();\n    \n    // 分块处理表格数据\n    $sheet-\u003echunk(100, function (SheetCollection $collection) {\n        $chunkArray = $collection-\u003etoArray();\n        \n        print_r($chunkArray); // [['id' =\u003e 1, 'name' =\u003e 'Brakus', 'email' =\u003e 'treutel@eg.com', 'created_at' =\u003e '...']]\n    });\n    \n});\n```\n\n获取指定表格内容\n```php\nuse Dcat\\EasyExcel\\Excel;\nuse Dcat\\EasyExcel\\Support\\SheetCollection;\n\n// 获取第一个表格内容\n$firstSheet = Excel::import('/tmp/users.xlsx')-\u003efirst()-\u003etoArray();\n\n\n// 获取最后一次保存前打开的表格内容\n$activeSheet = Excel::import('/tmp/users.xlsx')-\u003eactive()-\u003etoArray();\n\n\n// 获取指定名称或序号的表格内容\n$sheet = Excel::import('/tmp/users.xlsx')-\u003esheet('Sheet1')-\u003etoArray();\n$sheet = Excel::import('/tmp/users.xlsx')-\u003esheet(0)-\u003etoArray();\n\n\n// 分块处理表格内容\nExcel::import('/tmp/users.xlsx')\n    -\u003efirst()\n    -\u003echunk(1000, function (SheetCollection $collection) {\n        $collection = $collection-\u003ekeyBy('id');\n    });\n```\n\n更多导入功能请参考[文档](https://jqhph.github.io/easy-excel/docs/master/import.html)。\n\n\n## License\n[The MIT License (MIT)](LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjqhph%2Feasy-excel","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjqhph%2Feasy-excel","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjqhph%2Feasy-excel/lists"}