-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsearch.php
More file actions
51 lines (39 loc) · 1.51 KB
/
search.php
File metadata and controls
51 lines (39 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
class search{
protected $objPHPExcel;
protected $cellValues;
function __construct($filename){
$this->objPHPExcel = PHPExcel_IOFactory::load($filename);
}
public function getCellValues($force = false){
if ( !is_null($this->cellValues) && $force === false ){
return $this->cellValues;
}
$currentIndex = $this->objPHPExcel->getActiveSheetIndex();
$this->objPHPExcel->setActiveSheetIndex(0);
$sheet = $this->objPHPExcel->getActiveSheet();
$highestColumn = $sheet->getHighestColumn();
$highestColumnIndex = PHPExcel_Cell::columnIndexFromString($highestColumn);
$highestRow= $sheet->getHighestRow();
$this->cellValues = array();
for ( $i =0 ; $i < $highestColumnIndex; $i++ ){
$column = PHPExcel_Cell::stringFromColumnIndex($i);
for ( $j = 1; $j <= $highestRow; $j++ ){
$this->cellValues[$column . $j] = $sheet->getCellByColumnAndRow($i, $j)->getValue();
}
}
$this->objPHPExcel->setActiveSheetIndex($currentIndex);
return $this->cellValues;
}
public function getCellByValue($search) {
$nonPrintableChars = array("\n", "\r", "\t", "\s");
$search = str_replace($nonPrintableChars, '', $search);
foreach ( $this->getCellValues() as $cell => $value ){
if ( strcasecmp(str_replace($nonPrintableChars, '', $value), $search) == 0 ){
return $cell;
}
}
return false;
}
}
?>