Properties.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. use PhpOffice\PhpSpreadsheet\IOFactory;
  3. require __DIR__ . '/../Header.php';
  4. $inputFileType = 'Xls';
  5. $inputFileName = __DIR__ . '/sampleData/example1.xls';
  6. // Create a new Reader of the type defined in $inputFileType
  7. $reader = IOFactory::createReader($inputFileType);
  8. // Load $inputFileName to a PhpSpreadsheet Object
  9. $spreadsheet = $reader->load($inputFileName);
  10. // Read the document's creator property
  11. $creator = $spreadsheet->getProperties()->getCreator();
  12. $helper->log('<b>Document Creator: </b>' . $creator);
  13. // Read the Date when the workbook was created (as a PHP timestamp value)
  14. $creationDatestamp = $spreadsheet->getProperties()->getCreated();
  15. // Format the date and time using the standard PHP date() function
  16. $creationDate = date('l, d<\s\up>S</\s\up> F Y', $creationDatestamp);
  17. $creationTime = date('g:i A', $creationDatestamp);
  18. $helper->log('<b>Created On: </b>' . $creationDate . ' at ' . $creationTime);
  19. // Read the name of the last person to modify this workbook
  20. $modifiedBy = $spreadsheet->getProperties()->getLastModifiedBy();
  21. $helper->log('<b>Last Modified By: </b>' . $modifiedBy);
  22. // Read the Date when the workbook was last modified (as a PHP timestamp value)
  23. $modifiedDatestamp = $spreadsheet->getProperties()->getModified();
  24. // Format the date and time using the standard PHP date() function
  25. $modifiedDate = date('l, d<\s\up>S</\s\up> F Y', $modifiedDatestamp);
  26. $modifiedTime = date('g:i A', $modifiedDatestamp);
  27. $helper->log('<b>Last Modified On: </b>' . $modifiedDate . ' at ' . $modifiedTime);
  28. // Read the workbook title property
  29. $workbookTitle = $spreadsheet->getProperties()->getTitle();
  30. $helper->log('<b>Title: </b>' . $workbookTitle);
  31. // Read the workbook description property
  32. $description = $spreadsheet->getProperties()->getDescription();
  33. $helper->log('<b>Description: </b>' . $description);
  34. // Read the workbook subject property
  35. $subject = $spreadsheet->getProperties()->getSubject();
  36. $helper->log('<b>Subject: </b>' . $subject);
  37. // Read the workbook keywords property
  38. $keywords = $spreadsheet->getProperties()->getKeywords();
  39. $helper->log('<b>Keywords: </b>' . $keywords);
  40. // Read the workbook category property
  41. $category = $spreadsheet->getProperties()->getCategory();
  42. $helper->log('<b>Category: </b>' . $category);
  43. // Read the workbook company property
  44. $company = $spreadsheet->getProperties()->getCompany();
  45. $helper->log('<b>Company: </b>' . $company);
  46. // Read the workbook manager property
  47. $manager = $spreadsheet->getProperties()->getManager();
  48. $helper->log('<b>Manager: </b>' . $manager);
  49. $s = new \PhpOffice\PhpSpreadsheet\Helper\Sample();