I am trying to export an excel with a stored procedure that I have created, for this it sent the parameters and everything is fine, it returns a complete array, but there are some null values.
So I do the following (execute the query with static function)
$datos_mmu = S_Reporte_MMU_Cedente::get_reporte_mmu_cedente($id_cedente,$id_cartera,$tipo_mmu,$tipo_reporte);
Then I pass the data to use
Maatwebsite /excel (I have exported the excel facade), and I do it this way:
return Excel::create('Reporte Mmu', function($excel) use ($datos_mmu){
$excel->sheet('Excel sheet', function($sheet) use ($datos_mmu) {
$sheet->fromArray($datos_mmu);
});
})->export('xls');
But when I try to download it gives me the error
Object of class stdClass could not be converted to string
So I don't know if I get that error because I have null values or because it's done in another way. The array has to be dynamic since I do all this with stored procedures and the columns can change.
I have tried to do it in the following way but it doesn't work.
$array_data = [];
for ($c = 0;$c<sizeof($datos_mmu);$c++)
{
foreach ($datos_mmu[$c] as $i=>$cedente)
{
$array[$i] = (array)$cedente;
}
array_merge($array_data,$array);
}
Well it turns out that after so much searching I came to the conclusion that it was done in the following way dynamically
First I declare an
$array_data
empty and thenpush
I have to enter the array.After with two foreach
The first is that I take the data data that has the keys and the data, Example:
Something like this, then with the second foreach I go through it internally one by one to form the array and make it look like this
And once formed I can pass the variable that forms which would be
$array_data
and will download the file. I hope this is useful, regards.