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.

70 lines
2.2 KiB

  1. <?php
  2. ?>
  3. <html>
  4. <head>
  5. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  6. <title>PHPExcel Reader Example #15</title>
  7. </head>
  8. <body>
  9. <h1>PHPExcel Reader Example #15</h1>
  10. <h2>Simple File Reader for Tab-Separated Value File using the Advanced Value Binder</h2>
  11. <?php
  12. /** Include path **/
  13. set_include_path(get_include_path() . PATH_SEPARATOR . '../../../Classes/');
  14. /** PHPExcel_IOFactory */
  15. include 'PHPExcel/IOFactory.php';
  16. PHPExcel_Cell::setValueBinder( new PHPExcel_Cell_AdvancedValueBinder() );
  17. $inputFileType = 'CSV';
  18. $inputFileName = './sampleData/example1.tsv';
  19. $objReader = PHPExcel_IOFactory::createReader($inputFileType);
  20. echo 'Loading file ',pathinfo($inputFileName,PATHINFO_BASENAME),' into WorkSheet #1 using IOFactory with a defined reader type of ',$inputFileType,'<br />';
  21. $objReader->setDelimiter("\t");
  22. $objPHPExcel = $objReader->load($inputFileName);
  23. $objPHPExcel->getActiveSheet()->setTitle(pathinfo($inputFileName,PATHINFO_BASENAME));
  24. echo '<hr />';
  25. echo $objPHPExcel->getSheetCount(),' worksheet',(($objPHPExcel->getSheetCount() == 1) ? '' : 's'),' loaded<br /><br />';
  26. $loadedSheetNames = $objPHPExcel->getSheetNames();
  27. foreach($loadedSheetNames as $sheetIndex => $loadedSheetName) {
  28. echo '<b>Worksheet #',$sheetIndex,' -> ',$loadedSheetName,' (Formatted)</b><br />';
  29. $objPHPExcel->setActiveSheetIndexByName($loadedSheetName);
  30. $sheetData = $objPHPExcel->getActiveSheet()->toArray(null,true,true,true);
  31. var_dump($sheetData);
  32. echo '<br />';
  33. }
  34. echo '<hr />';
  35. foreach($loadedSheetNames as $sheetIndex => $loadedSheetName) {
  36. echo '<b>Worksheet #',$sheetIndex,' -> ',$loadedSheetName,' (Unformatted)</b><br />';
  37. $objPHPExcel->setActiveSheetIndexByName($loadedSheetName);
  38. $sheetData = $objPHPExcel->getActiveSheet()->toArray(null,true,false,true);
  39. var_dump($sheetData);
  40. echo '<br />';
  41. }
  42. echo '<hr />';
  43. foreach($loadedSheetNames as $sheetIndex => $loadedSheetName) {
  44. echo '<b>Worksheet #',$sheetIndex,' -> ',$loadedSheetName,' (Raw)</b><br />';
  45. $objPHPExcel->setActiveSheetIndexByName($loadedSheetName);
  46. $sheetData = $objPHPExcel->getActiveSheet()->toArray(null,false,false,true);
  47. var_dump($sheetData);
  48. echo '<br />';
  49. }
  50. ?>
  51. <body>
  52. </html>