I get reference from here : https://laravel-excel.maatwebsite.nl/docs/3.0/getting-started/basics
So I use version 3
My controller like this :
public function exportToExcel(Request $request)
{
$data = $request->all();
$exporter = app()->makeWith(SummaryExport::class, compact('data'));
return $exporter->download('Summary.xlsx');
}
My script export to excel like this :
namespace App\Exports;
use App\Repositories\ItemRepository;
use Maatwebsite\Excel\Concerns\FromCollection;
use Maatwebsite\Excel\Concerns\Exportable;
use Maatwebsite\Excel\Concerns\WithHeadings;
class SummaryExport implements FromCollection, WithHeadings {
use Exportable;
protected $itemRepository;
protected $data;
public function __construct(ItemRepository $itemRepository, $data) {
$this->itemRepository = $itemRepository;
$this->data = $data;
}
public function collection()
{
$items = $this->itemRepository->getSummary($this->data);
return $items;
}
public function headings(): array
{
return [
'No',
'Item Number',
'Sold Quantity',
'Profit'
];
}
}
If the script executed, the result like this :
I want to add some description or title above the table and I want to sum sold quantity column and profit column
So I want the result like this :
I had read the documentation and search in the google, but I don't find the solution
Is there anyone who can help?
via Chebli Mohamed


Aucun commentaire:
Enregistrer un commentaire