23_Sharedstyles.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. use PhpOffice\PhpSpreadsheet\Spreadsheet;
  3. use PhpOffice\PhpSpreadsheet\Style\Border;
  4. use PhpOffice\PhpSpreadsheet\Style\Fill;
  5. use PhpOffice\PhpSpreadsheet\Style\Style;
  6. require __DIR__ . '/../Header.php';
  7. // Create new Spreadsheet object
  8. $helper->log('Create new Spreadsheet object');
  9. $spreadsheet = new Spreadsheet();
  10. // Set document properties
  11. $helper->log('Set document properties');
  12. $spreadsheet->getProperties()->setCreator('Maarten Balliauw')
  13. ->setLastModifiedBy('Maarten Balliauw')
  14. ->setTitle('Office 2007 XLSX Test Document')
  15. ->setSubject('Office 2007 XLSX Test Document')
  16. ->setDescription('Test document for Office 2007 XLSX, generated using PHP classes.')
  17. ->setKeywords('office 2007 openxml php')
  18. ->setCategory('Test result file');
  19. // Add some data
  20. $helper->log('Add some data');
  21. $spreadsheet->setActiveSheetIndex(0);
  22. $sharedStyle1 = new Style();
  23. $sharedStyle2 = new Style();
  24. $sharedStyle1->applyFromArray(
  25. ['fill' => [
  26. 'fillType' => Fill::FILL_SOLID,
  27. 'color' => ['argb' => 'FFCCFFCC'],
  28. ],
  29. 'borders' => [
  30. 'bottom' => ['borderStyle' => Border::BORDER_THIN],
  31. 'right' => ['borderStyle' => Border::BORDER_MEDIUM],
  32. ],
  33. ]
  34. );
  35. $sharedStyle2->applyFromArray(
  36. ['fill' => [
  37. 'fillType' => Fill::FILL_SOLID,
  38. 'color' => ['argb' => 'FFFFFF00'],
  39. ],
  40. 'borders' => [
  41. 'bottom' => ['borderStyle' => Border::BORDER_THIN],
  42. 'right' => ['borderStyle' => Border::BORDER_MEDIUM],
  43. ],
  44. ]
  45. );
  46. $spreadsheet->getActiveSheet()->duplicateStyle($sharedStyle1, 'A1:T100');
  47. $spreadsheet->getActiveSheet()->duplicateStyle($sharedStyle2, 'C5:R95');
  48. // Save
  49. $helper->write($spreadsheet, __FILE__);