【发布时间】:2014-11-30 04:18:14
【问题描述】:
我在使用 phpexcel-laravel 时遇到了读取文件 .xls 的问题。我在这里https://github.com/Maatwebsite/Laravel-Excel 使用phpexcel,我想读取文件 .xls 中的数据。我的 .xls 有 2 列,列 id 和列名,我运行函数 getFile,我收到消息错误是“无法打开读取!文件不存在”。我不知道如何解决。你能指导我吗?谢谢!
我的控制器:
public function getFile(){
$results=array();
Excel::load('file/test.xls', function($reader) {
$results = $reader->select(array('id', 'name'))->get()->toArray();
});
$data = array(
'results' = $results;
);
return View::make('show_excel',$data)->render();
}
我的看法:
@if(!empty($results))
<table class="table table-striped table-bordered">
<thead>
<tr>
<th>ID</th>
<th>name</th>
</tr>
</thead>
@foreach ($results as $row)
<tr>
<td>{{$row->id}}</td>
<td>{{$row->name}}</td>
</tr>
@endforeach
</table>
@endif
【问题讨论】:
-
您是否尝试过将文件的完整路径传递给 Excel::load()?
标签: laravel-4