| Version | Date | Notes | By |
|---|---|---|---|
| 0.1 | 2017-05-19 | Initial release | ROB |
This class may be reviewed in the future to lessen the ammount of PHPExcel functions that need to be called, so as to reduce code bloat.
PHPExcel is the exporter you use when you wish to export excel files with complex formating and/or graphics. Review the PHPExcel documentation for all the formating possibilities / graphics that are possible to create.
You will need to create a class that extends PHPExcelExporter:
<?php
namespace WeMake\Services\TechnicalAudits;
use WeMake\Models\TechnicalAudits\Audit;
use WeMake\Models\TechnicalAudits\AuditStatus;
use WeMake\Services\Core\PHPExcelExporter;
/**
* Class AuditingScheduleAuditsExporter
*
* @package OneVet\Interfaces
*/
class AuditingScheduleAuditsExporter extends PHPExcelExporter
{
/**
* @var string
*/
protected $filename = 'auditing_schedule_report';
/**
* Generates report
*
* Note: pass as many parameters as you need to complete the form
* @param $request - required
* @param $auditingSchedule
* @param ...
* ...
*/
public function generateReport($request, $auditingSchedule, ...)
{
// initiate generation and download of the sheets defined in the callback (3rd parameter)
// - param 1 - request
// - param 2 - ?
// - param 3 - callback called before excel generation (used to define the sheets).
// - param 4 - if the default callback is to be appended (if you are designing your own
// report set this to false)
$this->download($request, [], function ($excel) use ($auditingSchedule, ...) {
// initiate generation of excel sheet (execute this function as many times as there are sheets)
// - param 1 - name of the sheet (will appear in excel sheet tab so it must be translatable)
// - param 1 - callback called before creation of the sheet (used to define the sheet's contents).
$excel->sheet(trans('reports.auditing-schedule'), function ($sheet) use ($auditingSchedule, ...) {
// in here you can create cells, define styles and insert graphics
// as documented in the PHPExcel documentation
});
}, false);
}
}
Then, in a controller of your choosing, create a function similar to this:
/**
* Create Excel list of the audits in an auditing program and their current state
*
* @param ShowRequest $request
* @param AuditingSchedule $auditingSchedule
* @param AuditingScheduleAuditsExporter $exporter
*/
public function excelAudits(
ShowRequest $request,
AuditingSchedule $auditingSchedule,
AuditingScheduleAuditsExporter $exporter
) {
$exporter->generateReport($request, $auditingSchedule);
}