exampleWorkBookReader03.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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 #03</title>
  10. </head>
  11. <body>
  12. <h1>PHPExcel Reading WorkBook Data Example #03</h1>
  13. <h2>Read Custom Property Values for a WorkBook</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 = 'Excel2007';
  20. $inputFileName = './sampleData/example1.xlsx';
  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 an array list of any custom properties for this document **/
  27. $customPropertyList = $objPHPExcel->getProperties()->getCustomProperties();
  28. echo '<b>Custom Properties: </b><br />';
  29. /** Loop through the list of custom properties **/
  30. foreach($customPropertyList as $customPropertyName) {
  31. echo '<b>',$customPropertyName,': </b>';
  32. /** Retrieve the property value **/
  33. $propertyValue = $objPHPExcel->getProperties()->getCustomPropertyValue($customPropertyName);
  34. /** Retrieve the property type **/
  35. $propertyType = $objPHPExcel->getProperties()->getCustomPropertyType($customPropertyName);
  36. /** Manipulate properties as appropriate for display purposes **/
  37. switch($propertyType) {
  38. case 'i' : // integer
  39. $propertyType = 'integer number';
  40. break;
  41. case 'f' : // float
  42. $propertyType = 'floating point number';
  43. break;
  44. case 's' : // string
  45. $propertyType = 'string';
  46. break;
  47. case 'd' : // date
  48. $propertyValue = date('l, d<\s\up>S</\s\up> F Y g:i A',$propertyValue);
  49. $propertyType = 'date';
  50. break;
  51. case 'b' : // boolean
  52. $propertyValue = ($propertyValue) ? 'TRUE' : 'FALSE';
  53. $propertyType = 'boolean';
  54. break;
  55. }
  56. echo $propertyValue,' (',$propertyType,')<br />';
  57. }
  58. ?>
  59. <body>
  60. </html>