0
0

exampleReader08.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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 #08</title>
  10. </head>
  11. <body>
  12. <h1>PHPExcel Reader Example #08</h1>
  13. <h2>Simple File Reader Loading Several Named WorkSheets</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. // $inputFileType = 'Excel2007';
  21. // $inputFileType = 'Excel2003XML';
  22. // $inputFileType = 'OOCalc';
  23. // $inputFileType = 'Gnumeric';
  24. $inputFileName = './sampleData/example1.xls';
  25. $sheetnames = array('Data Sheet #1','Data Sheet #3');
  26. echo 'Loading file ',pathinfo($inputFileName,PATHINFO_BASENAME),' using IOFactory with a defined reader type of ',$inputFileType,'<br />';
  27. $objReader = PHPExcel_IOFactory::createReader($inputFileType);
  28. echo 'Loading Sheet',((count($sheetnames) == 1) ? '' : 's'),' "',implode('" and "',$sheetnames),'" only<br />';
  29. $objReader->setLoadSheetsOnly($sheetnames);
  30. $objPHPExcel = $objReader->load($inputFileName);
  31. echo '<hr />';
  32. echo $objPHPExcel->getSheetCount(),' worksheet',(($objPHPExcel->getSheetCount() == 1) ? '' : 's'),' loaded<br /><br />';
  33. $loadedSheetNames = $objPHPExcel->getSheetNames();
  34. foreach($loadedSheetNames as $sheetIndex => $loadedSheetName) {
  35. echo $sheetIndex,' -> ',$loadedSheetName,'<br />';
  36. }
  37. ?>
  38. <body>
  39. </html>