exampleWorkBookReader01.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. error_reporting(E_ALL);
  3. set_time_limit(0);
  4. date_default_timezone_set('Europe/London');
  5. ?>
  6. <html>
  7. <head>
  8. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  9. <title>PHPExcel Reading WorkBook Data Example #01</title>
  10. </head>
  11. <body>
  12. <h1>PHPExcel Reading WorkBook Data Example #01</h1>
  13. <h2>Read the WorkBook Properties</h2>
  14. <?php
  15. /** Include path **/
  16. set_include_path(get_include_path() . PATH_SEPARATOR . '../../../Classes/');
  17. /** PHPExcel_IOFactory */
  18. include 'PHPExcel/IOFactory.php';
  19. $inputFileType = 'Excel5';
  20. $inputFileName = './sampleData/example1.xls';
  21. /** Create a new Reader of the type defined in $inputFileType **/
  22. $objReader = PHPExcel_IOFactory::createReader($inputFileType);
  23. /** Load $inputFileName to a PHPExcel Object **/
  24. $objPHPExcel = $objReader->load($inputFileName);
  25. echo '<hr />';
  26. /** Read the document's creator property **/
  27. $creator = $objPHPExcel->getProperties()->getCreator();
  28. echo '<b>Document Creator: </b>',$creator,'<br />';
  29. /** Read the Date when the workbook was created (as a PHP timestamp value) **/
  30. $creationDatestamp = $objPHPExcel->getProperties()->getCreated();
  31. /** Format the date and time using the standard PHP date() function **/
  32. $creationDate = date('l, d<\s\up>S</\s\up> F Y',$creationDatestamp);
  33. $creationTime = date('g:i A',$creationDatestamp);
  34. echo '<b>Created On: </b>',$creationDate,' at ',$creationTime,'<br />';
  35. /** Read the name of the last person to modify this workbook **/
  36. $modifiedBy = $objPHPExcel->getProperties()->getLastModifiedBy();
  37. echo '<b>Last Modified By: </b>',$modifiedBy,'<br />';
  38. /** Read the Date when the workbook was last modified (as a PHP timestamp value) **/
  39. $modifiedDatestamp = $objPHPExcel->getProperties()->getModified();
  40. /** Format the date and time using the standard PHP date() function **/
  41. $modifiedDate = date('l, d<\s\up>S</\s\up> F Y',$modifiedDatestamp);
  42. $modifiedTime = date('g:i A',$modifiedDatestamp);
  43. echo '<b>Last Modified On: </b>',$modifiedDate,' at ',$modifiedTime,'<br />';
  44. /** Read the workbook title property **/
  45. $workbookTitle = $objPHPExcel->getProperties()->getTitle();
  46. echo '<b>Title: </b>',$workbookTitle,'<br />';
  47. /** Read the workbook description property **/
  48. $description = $objPHPExcel->getProperties()->getDescription();
  49. echo '<b>Description: </b>',$description,'<br />';
  50. /** Read the workbook subject property **/
  51. $subject = $objPHPExcel->getProperties()->getSubject();
  52. echo '<b>Subject: </b>',$subject,'<br />';
  53. /** Read the workbook keywords property **/
  54. $keywords = $objPHPExcel->getProperties()->getKeywords();
  55. echo '<b>Keywords: </b>',$keywords,'<br />';
  56. /** Read the workbook category property **/
  57. $category = $objPHPExcel->getProperties()->getCategory();
  58. echo '<b>Category: </b>',$category,'<br />';
  59. /** Read the workbook company property **/
  60. $company = $objPHPExcel->getProperties()->getCompany();
  61. echo '<b>Company: </b>',$company,'<br />';
  62. /** Read the workbook manager property **/
  63. $manager = $objPHPExcel->getProperties()->getManager();
  64. echo '<b>Manager: </b>',$manager,'<br />';
  65. ?>
  66. <body>
  67. </html>