PluginProbe
Visualizer – Tables & Charts Manager with Built-in AI Generator / 3.1.1
Visualizer – Tables & Charts Manager with Built-in AI Generator v3.1.1
4.0.8 4.0.7 4.0.6 4.0.5 4.0.4 4.0.3 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.1 3.1.2 3.1.3 3.10.0 3.10.1 3.10.10 3.10.11 3.10.12 3.10.13 3.10.14 3.10.15 3.10.2 3.10.3 All 149 releases
visualizer / vendor / phpoffice / phpexcel / Documentation / Examples / Reader / exampleReader12.php

exampleReader12.php in Visualizer – Tables & Charts Manager with Built-in AI Generator 3.1.1, at vendor/phpoffice/phpexcel/Documentation/Examples/Reader/exampleReader12.php

94 lines 2.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 #12</title>
14
15 </head>
16 <body>
17
18 <h1>PHPExcel Reader Example #12</h1>
19 <h2>Reading a Workbook in "Chunks" Using a Configurable Read Filter (Version 2)</h2>
20 <?php
21
22 /** Set Include path to point at the PHPExcel Classes folder **/
23 set_include_path(get_include_path() . PATH_SEPARATOR . '../../../Classes/');
24
25 /** Include 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/example2.xls';
35
36
37 /** Define a Read Filter class implementing PHPExcel_Reader_IReadFilter */
38 class chunkReadFilter implements PHPExcel_Reader_IReadFilter
39 {
40 private $_startRow = 0;
41
42 private $_endRow = 0;
43
44 /** Set the list of rows that we want to read */
45 public function setRows($startRow, $chunkSize) {
46 $this->_startRow = $startRow;
47 $this->_endRow = $startRow + $chunkSize;
48 }
49
50 public function readCell($column, $row, $worksheetName = '') {
51 // Only read the heading row, and the rows that are configured in $this->_startRow and $this->_endRow
52 if (($row == 1) || ($row >= $this->_startRow && $row < $this->_endRow)) {
53 return true;
54 }
55 return false;
56 }
57 }
58
59
60 echo 'Loading file ',pathinfo($inputFileName,PATHINFO_BASENAME),' using IOFactory with a defined reader type of ',$inputFileType,'<br />';
61 /** Create a new Reader of the type defined in $inputFileType **/
62 $objReader = PHPExcel_IOFactory::createReader($inputFileType);
63
64
65 echo '<hr />';
66
67
68 /** Define how many rows we want to read for each "chunk" **/
69 $chunkSize = 20;
70 /** Create a new Instance of our Read Filter **/
71 $chunkFilter = new chunkReadFilter();
72
73 /** Tell the Reader that we want to use the Read Filter that we've Instantiated **/
74 $objReader->setReadFilter($chunkFilter);
75
76 /** Loop to read our worksheet in "chunk size" blocks **/
77 for ($startRow = 2; $startRow <= 240; $startRow += $chunkSize) {
78 echo 'Loading WorkSheet using configurable filter for headings row 1 and for rows ',$startRow,' to ',($startRow+$chunkSize-1),'<br />';
79 /** Tell the Read Filter, the limits on which rows we want to read this iteration **/
80 $chunkFilter->setRows($startRow,$chunkSize);
81 /** Load only the rows that match our filter from $inputFileName to a PHPExcel Object **/
82 $objPHPExcel = $objReader->load($inputFileName);
83
84 // Do some processing here
85
86 $sheetData = $objPHPExcel->getActiveSheet()->toArray(null,true,true,true);
87 var_dump($sheetData);
88 echo '<br /><br />';
89 }
90
91
92 ?>
93 <body>
94 </html>