首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何在laravel中导入excel

如何在laravel中导入excel
EN

Stack Overflow用户
提问于 2020-05-20 18:04:52
回答 1查看 575关注 0票数 0

我需要用Laravel框架在PHP上导入excel表(csv或xlsx),我需要知道如何才能做到这一点。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-05-20 18:53:36

使用https://github.com/box/spouthttps://github.com/maatwebsite/Laravel-Excel

喷口速度更快,但Laravel有更多的功能.

导入示例:

代码语言:javascript
运行
复制
use Box\Spout\Reader\Common\Creator\ReaderEntityFactory;
$reader = ReaderEntityFactory::createReaderFromFile('/path/to/file.ext');
$reader->open($filePath);
foreach ($reader->getSheetIterator() as $sheet) {
    foreach ($sheet->getRowIterator() as $row) {
        // do stuff with the row
        $cells = $row->getCells();
    }
}
$reader->close();

在Laravel中,您可以直接导入模型:

代码语言:javascript
运行
复制
(new UsersImport)->import('users.xlsx', null, \Maatwebsite\Excel\Excel::XLSX);
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61919883

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档