01_Simple.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. use PhpOffice\PhpSpreadsheet\Spreadsheet;
  3. require __DIR__ . '/../Header.php';
  4. $spreadsheet = new Spreadsheet();
  5. $helper->log('Create new Spreadsheet object');
  6. $spreadsheet = new Spreadsheet();
  7. // Set document properties
  8. $helper->log('Set document properties');
  9. $spreadsheet->getProperties()
  10. ->setCreator('Maarten Balliauw')
  11. ->setLastModifiedBy('Maarten Balliauw')
  12. ->setTitle('PhpSpreadsheet Test Document')
  13. ->setSubject('PhpSpreadsheet Test Document')
  14. ->setDescription('Test document for PhpSpreadsheet, generated using PHP classes.')
  15. ->setKeywords('office PhpSpreadsheet php')
  16. ->setCategory('Test result file');
  17. // Add some data
  18. $helper->log('Add some data');
  19. $spreadsheet->setActiveSheetIndex(0)
  20. ->setCellValue('A1', 'Hello')
  21. ->setCellValue('B2', 'world!')
  22. ->setCellValue('C1', 'Hello')
  23. ->setCellValue('D2', 'world!');
  24. // Miscellaneous glyphs, UTF-8
  25. $spreadsheet->setActiveSheetIndex(0)
  26. ->setCellValue('A4', 'Miscellaneous glyphs')
  27. ->setCellValue('A5', 'éàèùâêîôûëïüÿäöüç');
  28. $spreadsheet->getActiveSheet()
  29. ->setCellValue('A8', "Hello\nWorld");
  30. $spreadsheet->getActiveSheet()
  31. ->getRowDimension(8)
  32. ->setRowHeight(-1);
  33. $spreadsheet->getActiveSheet()
  34. ->getStyle('A8')
  35. ->getAlignment()
  36. ->setWrapText(true);
  37. $value = "-ValueA\n-Value B\n-Value C";
  38. $spreadsheet->getActiveSheet()
  39. ->setCellValue('A10', $value);
  40. $spreadsheet->getActiveSheet()
  41. ->getRowDimension(10)
  42. ->setRowHeight(-1);
  43. $spreadsheet->getActiveSheet()
  44. ->getStyle('A10')
  45. ->getAlignment()
  46. ->setWrapText(true);
  47. $spreadsheet->getActiveSheet()
  48. ->getStyle('A10')
  49. ->setQuotePrefix(true);
  50. // Rename worksheet
  51. $helper->log('Rename worksheet');
  52. $spreadsheet->getActiveSheet()
  53. ->setTitle('Simple');
  54. // Save
  55. $helper->write($spreadsheet, __FILE__);