visualizer
/
vendor
/
phpoffice
/
phpexcel
/
Documentation
/
Examples
/
Reader
/
exampleReader10.php
exampleReader10.php in Visualizer – Tables & Charts Manager with Built-in AI Generator 3.1.1, at vendor/phpoffice/phpexcel/Documentation/Examples/Reader/exampleReader10.php
| 1 | <?php |
| 2 | |
| 3 | error_reporting(E_ALL); |
| 4 | set_time_limit(0); |
| 5 | |
| 6 | date_default_timezone_set('Europe/London'); |
| 7 | |
| 8 | ?> |
| 9 | <html> |
| 10 | <head> |
| 11 | <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> |
| 12 | |
| 13 | <title>PHPExcel Reader Example #10</title> |
| 14 | |
| 15 | </head> |
| 16 | <body> |
| 17 | |
| 18 | <h1>PHPExcel Reader Example #10</h1> |
| 19 | <h2>Simple File Reader Using a Configurable Read Filter</h2> |
| 20 | <?php |
| 21 | |
| 22 | /** Include path **/ |
| 23 | set_include_path(get_include_path() . PATH_SEPARATOR . '../../../Classes/'); |
| 24 | |
| 25 | /** PHPExcel_IOFactory */ |
| 26 | include 'PHPExcel/IOFactory.php'; |
| 27 | |
| 28 | |
| 29 | $inputFileType = 'Excel5'; |
| 30 | // $inputFileType = 'Excel2007'; |
| 31 | // $inputFileType = 'Excel2003XML'; |
| 32 | // $inputFileType = 'OOCalc'; |
| 33 | // $inputFileType = 'Gnumeric'; |
| 34 | $inputFileName = './sampleData/example1.xls'; |
| 35 | $sheetname = 'Data Sheet #3'; |
| 36 | |
| 37 | |
| 38 | class MyReadFilter implements PHPExcel_Reader_IReadFilter |
| 39 | { |
| 40 | private $_startRow = 0; |
| 41 | |
| 42 | private $_endRow = 0; |
| 43 | |
| 44 | private $_columns = array(); |
| 45 | |
| 46 | public function __construct($startRow, $endRow, $columns) { |
| 47 | $this->_startRow = $startRow; |
| 48 | $this->_endRow = $endRow; |
| 49 | $this->_columns = $columns; |
| 50 | } |
| 51 | |
| 52 | public function readCell($column, $row, $worksheetName = '') { |
| 53 | if ($row >= $this->_startRow && $row <= $this->_endRow) { |
| 54 | if (in_array($column,$this->_columns)) { |
| 55 | return true; |
| 56 | } |
| 57 | } |
| 58 | return false; |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | $filterSubset = new MyReadFilter(9,15,range('G','K')); |
| 63 | |
| 64 | |
| 65 | echo 'Loading file ',pathinfo($inputFileName,PATHINFO_BASENAME),' using IOFactory with a defined reader type of ',$inputFileType,'<br />'; |
| 66 | $objReader = PHPExcel_IOFactory::createReader($inputFileType); |
| 67 | echo 'Loading Sheet "',$sheetname,'" only<br />'; |
| 68 | $objReader->setLoadSheetsOnly($sheetname); |
| 69 | echo 'Loading Sheet using configurable filter<br />'; |
| 70 | $objReader->setReadFilter($filterSubset); |
| 71 | $objPHPExcel = $objReader->load($inputFileName); |
| 72 | |
| 73 | |
| 74 | echo '<hr />'; |
| 75 | |
| 76 | $sheetData = $objPHPExcel->getActiveSheet()->toArray(null,true,true,true); |
| 77 | var_dump($sheetData); |
| 78 | |
| 79 | |
| 80 | ?> |
| 81 | <body> |
| 82 | </html> |