I am exporting an excel using Laravel excel 3.1 by Maatwebsite. I want to map it with 2 headings and display it one below the other
I'm using WithHeadings, WithMapping, FromArray I'm getting the records, just the format that needs correction
<?php
namespace App\Exports;
use Modules\Program\Entities\Program;
use Modules\report\Entities\report;
use DB;
use Maatwebsite\Excel\Concerns\FromArray;
use Maatwebsite\Excel\Concerns\WithTitle;
use Maatwebsite\Excel\Concerns\WithHeadings;
use Maatwebsite\Excel\Concerns\ShouldAutoSize;
use Maatwebsite\Excel\Concerns\WithMapping;
class reportPerDaySheet implements FromArray, WithTitle, WithHeadings, ShouldAutoSize, WithMapping
{
private $year;
private $day;
private $month;
public function __construct(int $year, int $month, int $day)
{
$this->year = $year;
$this->day = $day;
$this->month = $month;
}
public function array():array
{
$reportOut = DB::table('reports')->join('programs','programs.program_id','=','reports.program_id')->whereMonth('report_dateofreport', $this->month)->whereday('report_dateofreport', $this->day)->get()->toArray();
return $reportOut;
}
public function map($reportOut):array
{
return [
[
$reportOut->program_programname,
$reportOut->program_projectlead,
$reportOut->program_dse,
$reportOut->program_extserviceprovider,
$reportOut->program_programid,
$reportOut->program_datatype,
],
[
$reportOut->report_id,
$reportOut->report_date,
$reportOut->report_url,
$reportOut->report_username,
$reportOut->report_reportertype,
$reportOut->report_productname,
$reportOut->report_verbatim,
$reportOut->report_priority,
$reportOut->report_aeraised,
]
];
}
public function title(): string
{
return $this->day .' '. date("F", mktime(0,0,0,$this->month,1)) .' '. $this->year;
}
public function headings(): array
{
return[
[
'Program Name',
'Project Lead',
'DS&E Contact',
'Name of external service provider',
'Prepared By',
'External Service Provider Contact Information',
'Time Period Covered',
'Program ID',
'Date of Report',
'Data Type',
'Signature'
],
[
'Id',
'Date of report',
'Date',
'URL',
'Username',
'Reporter Type',
'Product Name',
'Verbatim',
'Priority',
'AE Raised',
'User',
'Date From',
'Date Till',
'Record Created At',
'Record Updated At'
]
];
}
}
Desired Output https://imgur.com/rHYl0YS
Current Output https://imgur.com/P06CYvt
from Newest questions tagged laravel-5 - Stack Overflow http://bit.ly/2WQdHTH
via IFTTT
Aucun commentaire:
Enregistrer un commentaire