largeSpreadsheet.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. // Create new Spreadsheet object
  3. use PhpOffice\PhpSpreadsheet\Spreadsheet;
  4. $helper->log('Create new Spreadsheet object');
  5. $spreadsheet = new Spreadsheet();
  6. // Set document properties
  7. $helper->log('Set properties');
  8. $spreadsheet->getProperties()->setCreator('Maarten Balliauw')
  9. ->setLastModifiedBy('Maarten Balliauw')
  10. ->setTitle('Office 2007 XLSX Test Document')
  11. ->setSubject('Office 2007 XLSX Test Document')
  12. ->setDescription('Test document for Office 2007 XLSX, generated using PHP classes.')
  13. ->setKeywords('office 2007 openxml php')
  14. ->setCategory('Test result file');
  15. // Create a first sheet
  16. $helper->log('Add data');
  17. $spreadsheet->setActiveSheetIndex(0);
  18. $spreadsheet->getActiveSheet()->setCellValue('A1', 'Firstname');
  19. $spreadsheet->getActiveSheet()->setCellValue('B1', 'Lastname');
  20. $spreadsheet->getActiveSheet()->setCellValue('C1', 'Phone');
  21. $spreadsheet->getActiveSheet()->setCellValue('D1', 'Fax');
  22. $spreadsheet->getActiveSheet()->setCellValue('E1', 'Is Client ?');
  23. // Hide "Phone" and "fax" column
  24. $helper->log("Hide 'Phone' and 'fax' columns");
  25. $spreadsheet->getActiveSheet()->getColumnDimension('C')->setVisible(false);
  26. $spreadsheet->getActiveSheet()->getColumnDimension('D')->setVisible(false);
  27. // Set outline levels
  28. $helper->log('Set outline levels');
  29. $spreadsheet->getActiveSheet()->getColumnDimension('E')->setOutlineLevel(1)
  30. ->setVisible(false)
  31. ->setCollapsed(true);
  32. // Freeze panes
  33. $helper->log('Freeze panes');
  34. $spreadsheet->getActiveSheet()->freezePane('A2');
  35. // Rows to repeat at top
  36. $helper->log('Rows to repeat at top');
  37. $spreadsheet->getActiveSheet()->getPageSetup()->setRowsToRepeatAtTopByStartAndEnd(1, 1);
  38. // Add data
  39. for ($i = 2; $i <= 5000; ++$i) {
  40. $spreadsheet->getActiveSheet()->setCellValue('A' . $i, "FName $i")
  41. ->setCellValue('B' . $i, "LName $i")
  42. ->setCellValue('C' . $i, "PhoneNo $i")
  43. ->setCellValue('D' . $i, "FaxNo $i")
  44. ->setCellValue('E' . $i, true);
  45. }
  46. return $spreadsheet;