For God so loved the world, that He gave His only begotten Son, that all who believe in Him should not perish but have everlasting life
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

55 lines
1.6 KiB

  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 #04</title>
  10. </head>
  11. <body>
  12. <h1>PHPExcel Reading WorkBook Data Example #04</h1>
  13. <h2>Get a List of the Worksheets in 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 = 'Excel5';
  20. $inputFileName = './sampleData/example2.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. echo 'Reading the number of Worksheets in the WorkBook<br />';
  27. /** Use the PHPExcel object's getSheetCount() method to get a count of the number of WorkSheets in the WorkBook */
  28. $sheetCount = $objPHPExcel->getSheetCount();
  29. echo 'There ',(($sheetCount == 1) ? 'is' : 'are'),' ',$sheetCount,' WorkSheet',(($sheetCount == 1) ? '' : 's'),' in the WorkBook<br /><br />';
  30. echo 'Reading the names of Worksheets in the WorkBook<br />';
  31. /** Use the PHPExcel object's getSheetNames() method to get an array listing the names/titles of the WorkSheets in the WorkBook */
  32. $sheetNames = $objPHPExcel->getSheetNames();
  33. foreach($sheetNames as $sheetIndex => $sheetName) {
  34. echo 'WorkSheet #',$sheetIndex,' is named "',$sheetName,'"<br />';
  35. }
  36. ?>
  37. <body>
  38. </html>