Php 在laravel excel中导入基础知识
我试图了解如何使用laravel/excel导入我的excel文件 我试着这样做:Php 在laravel excel中导入基础知识,php,excel,laravel,Php,Excel,Laravel,我试图了解如何使用laravel/excel导入我的excel文件 我试着这样做: public function import() { $path = public_path(); Excel::load($path.'/file.xlsx', function($reader) { $firstrow = $reader->first()->toArray(); dd($firstrow)
public function import()
{
$path = public_path();
Excel::load($path.'/file.xlsx', function($reader) {
$firstrow = $reader->first()->toArray();
dd($firstrow);
});
}
但是当我扔掉任何东西时,不要从拉威尔那里得到任何垃圾
这是我的excel中的数据:
item spool junta
1 test1 j1
2 test2 j2
3 test3 j3
是一个简单的文件只是为了测试,但什么也没有发生,我只是得到一个没有我的转储空白页
提前感谢您的帮助 您可以使用以下代码加载此.xls文件:
$post = new your_modelname;
$post-> Excel::load('your_sheet.xls', function($reader) {
$reader->setDateColumns(array(
'created_at', // for timestamp
'updated_at' ));
})->get();
试试这个,希望它能起作用。这就是我导入文件的方式,它可以完美地工作
$file = $request->file('userfile');
Excel::load($file, function($reader)
{
foreach ($reader->toArray() as $row)
{
dd($row);
// fire your query here to insert data to db...
}
}