exampleReader16.php 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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 Reader Example #16</title>
  10. </head>
  11. <body>
  12. <h1>PHPExcel Reader Example #16</h1>
  13. <h2>Handling Loader Exceptions using Try/Catch</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. $inputFileName = './sampleData/example_1.xls';
  20. echo 'Loading file ',pathinfo($inputFileName,PATHINFO_BASENAME),' using IOFactory to identify the format<br />';
  21. try {
  22. $objPHPExcel = PHPExcel_IOFactory::load($inputFileName);
  23. } catch(PHPExcel_Reader_Exception $e) {
  24. die('Error loading file "'.pathinfo($inputFileName,PATHINFO_BASENAME).'": '.$e->getMessage());
  25. }
  26. echo '<hr />';
  27. $sheetData = $objPHPExcel->getActiveSheet()->toArray(null,true,true,true);
  28. var_dump($sheetData);
  29. ?>
  30. <body>
  31. </html>