WithDefaultStylesTest.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. namespace Maatwebsite\Excel\Tests\Concerns;
  3. use Maatwebsite\Excel\Concerns\Exportable;
  4. use Maatwebsite\Excel\Concerns\FromArray;
  5. use Maatwebsite\Excel\Concerns\WithDefaultStyles;
  6. use Maatwebsite\Excel\Tests\TestCase;
  7. use PhpOffice\PhpSpreadsheet\Style\Fill;
  8. use PhpOffice\PhpSpreadsheet\Style\Style;
  9. class WithDefaultStylesTest extends TestCase
  10. {
  11. /**
  12. * @test
  13. */
  14. public function can_configure_default_styles()
  15. {
  16. $export = new class implements FromArray, WithDefaultStyles
  17. {
  18. use Exportable;
  19. public function defaultStyles(Style $defaultStyle)
  20. {
  21. return [
  22. 'fill' => [
  23. 'fillType' => Fill::FILL_SOLID,
  24. 'startColor' => ['argb' => 'fff2f2f2'],
  25. ],
  26. ];
  27. }
  28. public function array(): array
  29. {
  30. return [
  31. ['A1', 'B1', 'C1'],
  32. ['A2', 'B2', 'C2'],
  33. ];
  34. }
  35. };
  36. $export->store('with-default-styles.xlsx');
  37. $spreadsheet = $this->read(__DIR__ . '/../Data/Disks/Local/with-default-styles.xlsx', 'Xlsx');
  38. $sheet = $spreadsheet->getDefaultStyle();
  39. $this->assertEquals(Fill::FILL_SOLID, $sheet->getFill()->getFillType());
  40. $this->assertEquals('fff2f2f2', $sheet->getFill()->getStartColor()->getARGB());
  41. }
  42. }