40_Duplicate_style.php 1007 B

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
  3. use PhpOffice\PhpSpreadsheet\Spreadsheet;
  4. use PhpOffice\PhpSpreadsheet\Style\Style;
  5. require __DIR__ . '/../Header.php';
  6. $helper->log('Create new Spreadsheet object');
  7. $spreadsheet = new Spreadsheet();
  8. $worksheet = $spreadsheet->getActiveSheet();
  9. $helper->log('Create styles array');
  10. $styles = [];
  11. for ($i = 0; $i < 10; ++$i) {
  12. $style = new Style();
  13. $style->getFont()->setSize($i + 4);
  14. $styles[] = $style;
  15. }
  16. $helper->log('Add data (begin)');
  17. $t = microtime(true);
  18. for ($col = 1; $col <= 50; ++$col) {
  19. for ($row = 0; $row < 100; ++$row) {
  20. $str = ($row + $col);
  21. $style = $styles[$row % 10];
  22. $coord = Coordinate::stringFromColumnIndex($col) . ($row + 1);
  23. $worksheet->setCellValue($coord, $str);
  24. $worksheet->duplicateStyle($style, $coord);
  25. }
  26. }
  27. $d = microtime(true) - $t;
  28. $helper->log('Add data (end) . time: ' . round((string) ($d . 2)) . ' s');
  29. // Save
  30. $helper->write($spreadsheet, __FILE__);