【发布时间】:2015-05-15 12:54:07
【问题描述】:
在我的 laravel 4 项目中实现导出到 Excel。
所以我试图从这样的数组中生成 excel 文件:
//$results is taken with db query
$data = array();
foreach ($results as $result) {
$result->filed1 = 'some modification';
$result->filed2 = 'some modification2';
$data[] = $result;
}
Excel::create('Filename', function($excel) use($data) {
$excel->sheet('Sheetname', function($sheet) use($data) {
$sheet->fromArray($data);
});
})->export('xls');
但这会引发异常:
Object of class stdClass could not be converted to string
我做错了什么?
更新:
试过这个:
$data = get_object_vars($data);
导致:
get_object_vars() expects parameter 1 to be object, array given
这个:
$data = (array)$data;
导致初始错误。
【问题讨论】:
-
我认为您的配置遗漏了一些东西。仔细检查您的
app/config.php文件中的服务提供商和别名。