Hey guys. I'm using Nayjest/Grids and I can't use the ExcelExport. It's with a depreciated function there, so I'm trying manually. I followed the documentation and it works. But.... it's all messed up. How can I fix this?
Expected behavior:
I want this way:
ID | Created At | Updated At | Initials | Quantity
2 | 2018-06-20 09:45:30 | 2018-06-20 09:45:30 | EN | 聽 | 7
3 | 2018-06-20 09:45:30 | 2018-06-20 09:45:30 | IN | 聽 | 35
In other words, I need a header or an identification.
Actual behavior:
When I download the xlsx, I have this:
2 | 2018-06-20 09:45:30 | 2018-06-20 09:45:30 | EN | 聽 | 7
3 | 2018-06-20 09:45:30 | 2018-06-20 09:45:30 | IN | 聽 | 35
In the Nayjest/Grids I have this code:
protected function renderExcel()
{
/** @var Excel $excel */
$excel = app('excel');
$excel
->create($this->getFileName(), $this->getOnFileCreate())
->export(new PesoFuncaoExport, 'peso_funcao.xls');
}
So, this code does not work because the method create is depreciated. When I try to use the other methods, I cannot download the file, I click on the button, the page is refreshed but I can't download.
I'm using this code
protected function renderExcel()
{
/** @var Excel $excel */
$excel = app('excel');
$excel->download(new PesoFuncaoExport, 'peso_funcao.xlsx' );
// ->create($this->getFileName(), $this->getOnFileCreate())
// ->export(new PesoFuncaoExport, 'peso_funcao.xls');
}
Anyone can Help?
Hi @RafaelRodriguesFraga ,
Have you tried implementing the WithHeadings concern in your export class? (see Export concerns
You should then add a method to your export class with an array of heading names, e.g:
public function headings(): array
{
return [
'ID',
'Created At',
'Updated At',
'Initials',
'Quantity'
];
}
Please note that it looks like your content does have an extra (empty) column, compared to your heading row.
By the way, you should return the results of the download method as well.
Thanks for the answer and for the advice. It worked, thanks a bunch.
Another question:
public function collection()
{
return Invoice::all();
}
This will give me all records of my Model, right? I'm asking because I'm getting records that I don't need. How can I ignore these?

And Can I change the order of the records?
Showing Like This
ID | Created At | Updated At | Initials | Quantity
2 | 2018-06-20 09:45:30 | 2018-06-20 09:45:30 | EN | | 7
3 | 2018-06-20 09:45:30 | 2018-06-20 09:45:30 | IN | | 35
Changing quantity to be after ID, for example
ID | Quantity | Created At | Updated At | Initials
2 | 7 | 2018-06-20 | 09:45:30 | 2018-06-20 09:45:30 | EN
3 | 35 | 2018-06-20 09:45:30 | 2018-06-20 09:45:30 | IN
Hi @RafaelRodriguesFraga,
I haven't tested it myself (yet), but most likely this article will help you suit your needs:
Mapping data
You indeed need the WithMapping concern.
I had read this article, but didn't understand at the first time. I'll try here. Thanks guys
Thanks guys. It worked. I tried the FromQuery Interface and works perfectly for me. Betten than FromCollection.
Thanks a bunch for the help
Most helpful comment
Thanks guys. It worked. I tried the FromQuery Interface and works perfectly for me. Betten than FromCollection.
Thanks a bunch for the help