@@ -35,10 +35,10 @@ discard block |
||
35 | 35 | $objPHPExcel = $objReader->load($inputFileName); |
36 | 36 | $objPHPExcel->getActiveSheet()->setTitle(pathinfo($inputFileName,PATHINFO_BASENAME)); |
37 | 37 | foreach($inputFileNames as $sheet => $inputFileName) { |
38 | - echo 'Loading file ',pathinfo($inputFileName,PATHINFO_BASENAME),' into WorkSheet #',($sheet+2),' using IOFactory with a defined reader type of ',$inputFileType,'<br />'; |
|
39 | - $objReader->setSheetIndex($sheet+1); |
|
40 | - $objReader->loadIntoExisting($inputFileName,$objPHPExcel); |
|
41 | - $objPHPExcel->getActiveSheet()->setTitle(pathinfo($inputFileName,PATHINFO_BASENAME)); |
|
38 | + echo 'Loading file ',pathinfo($inputFileName,PATHINFO_BASENAME),' into WorkSheet #',($sheet+2),' using IOFactory with a defined reader type of ',$inputFileType,'<br />'; |
|
39 | + $objReader->setSheetIndex($sheet+1); |
|
40 | + $objReader->loadIntoExisting($inputFileName,$objPHPExcel); |
|
41 | + $objPHPExcel->getActiveSheet()->setTitle(pathinfo($inputFileName,PATHINFO_BASENAME)); |
|
42 | 42 | } |
43 | 43 | |
44 | 44 | |
@@ -47,11 +47,11 @@ discard block |
||
47 | 47 | echo $objPHPExcel->getSheetCount(),' worksheet',(($objPHPExcel->getSheetCount() == 1) ? '' : 's'),' loaded<br /><br />'; |
48 | 48 | $loadedSheetNames = $objPHPExcel->getSheetNames(); |
49 | 49 | foreach($loadedSheetNames as $sheetIndex => $loadedSheetName) { |
50 | - echo '<b>Worksheet #',$sheetIndex,' -> ',$loadedSheetName,'</b><br />'; |
|
51 | - $objPHPExcel->setActiveSheetIndexByName($loadedSheetName); |
|
52 | - $sheetData = $objPHPExcel->getActiveSheet()->toArray(null,true,true,true); |
|
53 | - var_dump($sheetData); |
|
54 | - echo '<br /><br />'; |
|
50 | + echo '<b>Worksheet #',$sheetIndex,' -> ',$loadedSheetName,'</b><br />'; |
|
51 | + $objPHPExcel->setActiveSheetIndexByName($loadedSheetName); |
|
52 | + $sheetData = $objPHPExcel->getActiveSheet()->toArray(null,true,true,true); |
|
53 | + var_dump($sheetData); |
|
54 | + echo '<br /><br />'; |
|
55 | 55 | } |
56 | 56 | |
57 | 57 |
@@ -39,31 +39,31 @@ |
||
39 | 39 | echo $objPHPExcel->getSheetCount(),' worksheet',(($objPHPExcel->getSheetCount() == 1) ? '' : 's'),' loaded<br /><br />'; |
40 | 40 | $loadedSheetNames = $objPHPExcel->getSheetNames(); |
41 | 41 | foreach($loadedSheetNames as $sheetIndex => $loadedSheetName) { |
42 | - echo '<b>Worksheet #',$sheetIndex,' -> ',$loadedSheetName,' (Formatted)</b><br />'; |
|
43 | - $objPHPExcel->setActiveSheetIndexByName($loadedSheetName); |
|
44 | - $sheetData = $objPHPExcel->getActiveSheet()->toArray(null,true,true,true); |
|
45 | - var_dump($sheetData); |
|
46 | - echo '<br />'; |
|
42 | + echo '<b>Worksheet #',$sheetIndex,' -> ',$loadedSheetName,' (Formatted)</b><br />'; |
|
43 | + $objPHPExcel->setActiveSheetIndexByName($loadedSheetName); |
|
44 | + $sheetData = $objPHPExcel->getActiveSheet()->toArray(null,true,true,true); |
|
45 | + var_dump($sheetData); |
|
46 | + echo '<br />'; |
|
47 | 47 | } |
48 | 48 | |
49 | 49 | echo '<hr />'; |
50 | 50 | |
51 | 51 | foreach($loadedSheetNames as $sheetIndex => $loadedSheetName) { |
52 | - echo '<b>Worksheet #',$sheetIndex,' -> ',$loadedSheetName,' (Unformatted)</b><br />'; |
|
53 | - $objPHPExcel->setActiveSheetIndexByName($loadedSheetName); |
|
54 | - $sheetData = $objPHPExcel->getActiveSheet()->toArray(null,true,false,true); |
|
55 | - var_dump($sheetData); |
|
56 | - echo '<br />'; |
|
52 | + echo '<b>Worksheet #',$sheetIndex,' -> ',$loadedSheetName,' (Unformatted)</b><br />'; |
|
53 | + $objPHPExcel->setActiveSheetIndexByName($loadedSheetName); |
|
54 | + $sheetData = $objPHPExcel->getActiveSheet()->toArray(null,true,false,true); |
|
55 | + var_dump($sheetData); |
|
56 | + echo '<br />'; |
|
57 | 57 | } |
58 | 58 | |
59 | 59 | echo '<hr />'; |
60 | 60 | |
61 | 61 | foreach($loadedSheetNames as $sheetIndex => $loadedSheetName) { |
62 | - echo '<b>Worksheet #',$sheetIndex,' -> ',$loadedSheetName,' (Raw)</b><br />'; |
|
63 | - $objPHPExcel->setActiveSheetIndexByName($loadedSheetName); |
|
64 | - $sheetData = $objPHPExcel->getActiveSheet()->toArray(null,false,false,true); |
|
65 | - var_dump($sheetData); |
|
66 | - echo '<br />'; |
|
62 | + echo '<b>Worksheet #',$sheetIndex,' -> ',$loadedSheetName,' (Raw)</b><br />'; |
|
63 | + $objPHPExcel->setActiveSheetIndexByName($loadedSheetName); |
|
64 | + $sheetData = $objPHPExcel->getActiveSheet()->toArray(null,false,false,true); |
|
65 | + var_dump($sheetData); |
|
66 | + echo '<br />'; |
|
67 | 67 | } |
68 | 68 | |
69 | 69 | ?> |
@@ -37,23 +37,23 @@ discard block |
||
37 | 37 | /** Define a Read Filter class implementing PHPExcel_Reader_IReadFilter */ |
38 | 38 | class chunkReadFilter implements PHPExcel_Reader_IReadFilter |
39 | 39 | { |
40 | - private $_startRow = 0; |
|
41 | - |
|
42 | - private $_endRow = 0; |
|
43 | - |
|
44 | - /** We expect a list of the rows that we want to read to be passed into the constructor */ |
|
45 | - public function __construct($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 were configured in the constructor |
|
52 | - if (($row == 1) || ($row >= $this->_startRow && $row < $this->_endRow)) { |
|
53 | - return true; |
|
54 | - } |
|
55 | - return false; |
|
56 | - } |
|
40 | + private $_startRow = 0; |
|
41 | + |
|
42 | + private $_endRow = 0; |
|
43 | + |
|
44 | + /** We expect a list of the rows that we want to read to be passed into the constructor */ |
|
45 | + public function __construct($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 were configured in the constructor |
|
52 | + if (($row == 1) || ($row >= $this->_startRow && $row < $this->_endRow)) { |
|
53 | + return true; |
|
54 | + } |
|
55 | + return false; |
|
56 | + } |
|
57 | 57 | } |
58 | 58 | |
59 | 59 | |
@@ -70,19 +70,19 @@ discard block |
||
70 | 70 | |
71 | 71 | /** Loop to read our worksheet in "chunk size" blocks **/ |
72 | 72 | for ($startRow = 2; $startRow <= 240; $startRow += $chunkSize) { |
73 | - echo 'Loading WorkSheet using configurable filter for headings row 1 and for rows ',$startRow,' to ',($startRow+$chunkSize-1),'<br />'; |
|
74 | - /** Create a new Instance of our Read Filter, passing in the limits on which rows we want to read **/ |
|
75 | - $chunkFilter = new chunkReadFilter($startRow,$chunkSize); |
|
76 | - /** Tell the Reader that we want to use the new Read Filter that we've just Instantiated **/ |
|
77 | - $objReader->setReadFilter($chunkFilter); |
|
78 | - /** Load only the rows that match our filter from $inputFileName to a PHPExcel Object **/ |
|
79 | - $objPHPExcel = $objReader->load($inputFileName); |
|
80 | - |
|
81 | - // Do some processing here |
|
82 | - |
|
83 | - $sheetData = $objPHPExcel->getActiveSheet()->toArray(null,true,true,true); |
|
84 | - var_dump($sheetData); |
|
85 | - echo '<br /><br />'; |
|
73 | + echo 'Loading WorkSheet using configurable filter for headings row 1 and for rows ',$startRow,' to ',($startRow+$chunkSize-1),'<br />'; |
|
74 | + /** Create a new Instance of our Read Filter, passing in the limits on which rows we want to read **/ |
|
75 | + $chunkFilter = new chunkReadFilter($startRow,$chunkSize); |
|
76 | + /** Tell the Reader that we want to use the new Read Filter that we've just Instantiated **/ |
|
77 | + $objReader->setReadFilter($chunkFilter); |
|
78 | + /** Load only the rows that match our filter from $inputFileName to a PHPExcel Object **/ |
|
79 | + $objPHPExcel = $objReader->load($inputFileName); |
|
80 | + |
|
81 | + // Do some processing here |
|
82 | + |
|
83 | + $sheetData = $objPHPExcel->getActiveSheet()->toArray(null,true,true,true); |
|
84 | + var_dump($sheetData); |
|
85 | + echo '<br /><br />'; |
|
86 | 86 | } |
87 | 87 | |
88 | 88 |
@@ -29,9 +29,9 @@ |
||
29 | 29 | $inputFileName = './sampleData/example_1.xls'; |
30 | 30 | echo 'Loading file ',pathinfo($inputFileName,PATHINFO_BASENAME),' using IOFactory to identify the format<br />'; |
31 | 31 | try { |
32 | - $objPHPExcel = PHPExcel_IOFactory::load($inputFileName); |
|
32 | + $objPHPExcel = PHPExcel_IOFactory::load($inputFileName); |
|
33 | 33 | } catch(\PHPExcel\Reader\Exception $e) { |
34 | - die('Error loading file "'.pathinfo($inputFileName,PATHINFO_BASENAME).'": '.$e->getMessage()); |
|
34 | + die('Error loading file "'.pathinfo($inputFileName,PATHINFO_BASENAME).'": '.$e->getMessage()); |
|
35 | 35 | } |
36 | 36 | |
37 | 37 |
@@ -37,23 +37,23 @@ discard block |
||
37 | 37 | /** Define a Read Filter class implementing PHPExcel_Reader_IReadFilter */ |
38 | 38 | class chunkReadFilter implements PHPExcel_Reader_IReadFilter |
39 | 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 | - } |
|
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 | 57 | } |
58 | 58 | |
59 | 59 | |
@@ -75,17 +75,17 @@ discard block |
||
75 | 75 | |
76 | 76 | /** Loop to read our worksheet in "chunk size" blocks **/ |
77 | 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); |
|
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 | 83 | |
84 | - // Do some processing here |
|
84 | + // Do some processing here |
|
85 | 85 | |
86 | - $sheetData = $objPHPExcel->getActiveSheet()->toArray(null,true,true,true); |
|
87 | - var_dump($sheetData); |
|
88 | - echo '<br /><br />'; |
|
86 | + $sheetData = $objPHPExcel->getActiveSheet()->toArray(null,true,true,true); |
|
87 | + var_dump($sheetData); |
|
88 | + echo '<br /><br />'; |
|
89 | 89 | } |
90 | 90 | |
91 | 91 |
@@ -37,26 +37,26 @@ |
||
37 | 37 | |
38 | 38 | class MyReadFilter implements PHPExcel_Reader_IReadFilter |
39 | 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 | - } |
|
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 | 60 | } |
61 | 61 | |
62 | 62 | $filterSubset = new MyReadFilter(9,15,range('G','K')); |
@@ -43,7 +43,7 @@ |
||
43 | 43 | |
44 | 44 | echo 'There are ',count($worksheetNames),' worksheet',((count($worksheetNames) == 1) ? '' : 's'),' in the workbook<br /><br />'; |
45 | 45 | foreach($worksheetNames as $worksheetName) { |
46 | - echo $worksheetName,'<br />'; |
|
46 | + echo $worksheetName,'<br />'; |
|
47 | 47 | } |
48 | 48 | |
49 | 49 |
@@ -46,7 +46,7 @@ |
||
46 | 46 | echo $objPHPExcel->getSheetCount(),' worksheet',(($objPHPExcel->getSheetCount() == 1) ? '' : 's'),' loaded<br /><br />'; |
47 | 47 | $loadedSheetNames = $objPHPExcel->getSheetNames(); |
48 | 48 | foreach($loadedSheetNames as $sheetIndex => $loadedSheetName) { |
49 | - echo $sheetIndex,' -> ',$loadedSheetName,'<br />'; |
|
49 | + echo $sheetIndex,' -> ',$loadedSheetName,'<br />'; |
|
50 | 50 | } |
51 | 51 | |
52 | 52 |
@@ -27,23 +27,23 @@ discard block |
||
27 | 27 | /** Define a Read Filter class implementing PHPExcel_Reader_IReadFilter */ |
28 | 28 | class chunkReadFilter implements PHPExcel_Reader_IReadFilter |
29 | 29 | { |
30 | - private $_startRow = 0; |
|
31 | - |
|
32 | - private $_endRow = 0; |
|
33 | - |
|
34 | - /** Set the list of rows that we want to read */ |
|
35 | - public function setRows($startRow, $chunkSize) { |
|
36 | - $this->_startRow = $startRow; |
|
37 | - $this->_endRow = $startRow + $chunkSize; |
|
38 | - } |
|
39 | - |
|
40 | - public function readCell($column, $row, $worksheetName = '') { |
|
41 | - // Only read the heading row, and the rows that are configured in $this->_startRow and $this->_endRow |
|
42 | - if (($row == 1) || ($row >= $this->_startRow && $row < $this->_endRow)) { |
|
43 | - return true; |
|
44 | - } |
|
45 | - return false; |
|
46 | - } |
|
30 | + private $_startRow = 0; |
|
31 | + |
|
32 | + private $_endRow = 0; |
|
33 | + |
|
34 | + /** Set the list of rows that we want to read */ |
|
35 | + public function setRows($startRow, $chunkSize) { |
|
36 | + $this->_startRow = $startRow; |
|
37 | + $this->_endRow = $startRow + $chunkSize; |
|
38 | + } |
|
39 | + |
|
40 | + public function readCell($column, $row, $worksheetName = '') { |
|
41 | + // Only read the heading row, and the rows that are configured in $this->_startRow and $this->_endRow |
|
42 | + if (($row == 1) || ($row >= $this->_startRow && $row < $this->_endRow)) { |
|
43 | + return true; |
|
44 | + } |
|
45 | + return false; |
|
46 | + } |
|
47 | 47 | } |
48 | 48 | |
49 | 49 | |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | /** Tell the Reader that we want to use the Read Filter that we've Instantiated **/ |
64 | 64 | /** and that we want to store it in contiguous rows/columns **/ |
65 | 65 | $objReader->setReadFilter($chunkFilter) |
66 | - ->setContiguous(true); |
|
66 | + ->setContiguous(true); |
|
67 | 67 | |
68 | 68 | |
69 | 69 | /** Instantiate a new PHPExcel object manually **/ |
@@ -74,13 +74,13 @@ discard block |
||
74 | 74 | /** Loop to read our worksheet in "chunk size" blocks **/ |
75 | 75 | /** $startRow is set to 2 initially because we always read the headings in row #1 **/ |
76 | 76 | for ($startRow = 2; $startRow <= 240; $startRow += $chunkSize) { |
77 | - echo 'Loading WorkSheet #',($sheet+1),' using configurable filter for headings row 1 and for rows ',$startRow,' to ',($startRow+$chunkSize-1),'<br />'; |
|
78 | - /** Tell the Read Filter, the limits on which rows we want to read this iteration **/ |
|
79 | - $chunkFilter->setRows($startRow,$chunkSize); |
|
77 | + echo 'Loading WorkSheet #',($sheet+1),' using configurable filter for headings row 1 and for rows ',$startRow,' to ',($startRow+$chunkSize-1),'<br />'; |
|
78 | + /** Tell the Read Filter, the limits on which rows we want to read this iteration **/ |
|
79 | + $chunkFilter->setRows($startRow,$chunkSize); |
|
80 | 80 | |
81 | 81 | /** Increment the worksheet index pointer for the Reader **/ |
82 | 82 | $objReader->setSheetIndex($sheet); |
83 | - /** Load only the rows that match our filter into a new worksheet in the PHPExcel Object **/ |
|
83 | + /** Load only the rows that match our filter into a new worksheet in the PHPExcel Object **/ |
|
84 | 84 | $objReader->loadIntoExisting($inputFileName,$objPHPExcel); |
85 | 85 | /** Set the worksheet title (to reference the "sheet" of data that we've loaded) **/ |
86 | 86 | /** and increment the sheet index as well **/ |
@@ -93,11 +93,11 @@ discard block |
||
93 | 93 | echo $objPHPExcel->getSheetCount(),' worksheet',(($objPHPExcel->getSheetCount() == 1) ? '' : 's'),' loaded<br /><br />'; |
94 | 94 | $loadedSheetNames = $objPHPExcel->getSheetNames(); |
95 | 95 | foreach($loadedSheetNames as $sheetIndex => $loadedSheetName) { |
96 | - echo '<b>Worksheet #',$sheetIndex,' -> ',$loadedSheetName,'</b><br />'; |
|
97 | - $objPHPExcel->setActiveSheetIndexByName($loadedSheetName); |
|
98 | - $sheetData = $objPHPExcel->getActiveSheet()->toArray(null,false,false,true); |
|
99 | - var_dump($sheetData); |
|
100 | - echo '<br />'; |
|
96 | + echo '<b>Worksheet #',$sheetIndex,' -> ',$loadedSheetName,'</b><br />'; |
|
97 | + $objPHPExcel->setActiveSheetIndexByName($loadedSheetName); |
|
98 | + $sheetData = $objPHPExcel->getActiveSheet()->toArray(null,false,false,true); |
|
99 | + var_dump($sheetData); |
|
100 | + echo '<br />'; |
|
101 | 101 | } |
102 | 102 | |
103 | 103 | ?> |