Skip to main content

Black Friday 2025! Only until December 1st: coupon FRIDAY25 for 40% off Yearly/Lifetime membership!

Read more here

clockobot/clockobot

46 stars
3 code files
View clockobot/clockobot on GitHub

composer.json

Open in GitHub
{
// ...
 
"require": {
// ...
"maatwebsite/excel": "^3.1",
// ...
},
 
// ...
}

app/Exports/ReportExport.php

Open in GitHub
use Illuminate\View\View;
use Maatwebsite\Excel\Concerns\Exportable;
use Maatwebsite\Excel\Concerns\FromView;
use Maatwebsite\Excel\Concerns\WithColumnWidths;
use Maatwebsite\Excel\Concerns\WithStyles;
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
 
class ReportExport implements FromView, WithColumnWidths, WithStyles
{
use Exportable;
 
public function __construct($data)
{
$this->data = $data;
}
 
// https://docs.laravel-excel.com/3.1/exports/from-view.html
public function view(): View
{
return view('exports.timesheet', [
'time_entries' => $this->data,
]);
}
 
public function columnWidths(): array
{
return [
'A' => 20,
'B' => 20,
'C' => 20,
'D' => 45,
'E' => 45,
'F' => 20,
'G' => 20,
'H' => 20,
'I' => 20,
];
}
 
public function styles(Worksheet $sheet)
{
return [
// Styling an entire column.
'A' => ['style' => ['alignment' => 'middle'], 'alignment' => ['wrapText' => true, 'vertical' => \PhpOffice\PhpSpreadsheet\Style\Alignment::VERTICAL_CENTER]],
'B' => ['style' => ['alignment' => 'middle'], 'alignment' => ['wrapText' => true, 'vertical' => \PhpOffice\PhpSpreadsheet\Style\Alignment::VERTICAL_CENTER]],
'C' => ['style' => ['alignment' => 'middle'], 'alignment' => ['wrapText' => true, 'vertical' => \PhpOffice\PhpSpreadsheet\Style\Alignment::VERTICAL_CENTER]],
'D' => ['style' => ['alignment' => 'middle'], 'alignment' => ['wrapText' => true, 'vertical' => \PhpOffice\PhpSpreadsheet\Style\Alignment::VERTICAL_CENTER]],
'E' => ['style' => ['alignment' => 'middle'], 'alignment' => ['wrapText' => true, 'vertical' => \PhpOffice\PhpSpreadsheet\Style\Alignment::VERTICAL_CENTER]],
'F' => ['style' => ['alignment' => 'middle'], 'alignment' => ['wrapText' => true, 'vertical' => \PhpOffice\PhpSpreadsheet\Style\Alignment::VERTICAL_CENTER]],
'G' => ['style' => ['alignment' => 'middle'], 'alignment' => ['wrapText' => true, 'vertical' => \PhpOffice\PhpSpreadsheet\Style\Alignment::VERTICAL_CENTER]],
'H' => ['style' => ['alignment' => 'middle'], 'alignment' => ['wrapText' => true, 'vertical' => \PhpOffice\PhpSpreadsheet\Style\Alignment::VERTICAL_CENTER, 'horizontal' => \PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_RIGHT]],
'I' => ['style' => ['alignment' => 'middle'], 'alignment' => ['wrapText' => true, 'vertical' => \PhpOffice\PhpSpreadsheet\Style\Alignment::VERTICAL_CENTER, 'horizontal' => \PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_RIGHT]],
];
}
}

app/Livewire/Reporting/ReportingIndex.php

Open in GitHub
use App\Exports\ReportExport;
use Livewire\Component;
use Maatwebsite\Excel\Facades\Excel;
 
class ReportingIndex extends Component
{
// ...
 
public function export()
{
// https://docs.laravel-excel.com/3.1/getting-started/
return Excel::download(new ReportExport($this->time_entries()), 'report.xlsx');
}
 
public function render()
{
return view('livewire.reporting.reporting-index');
}
}

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.