diff --git a/Classes/PHPExcel/Reader/Excel2007.php b/Classes/PHPExcel/Reader/Excel2007.php index 743f926..9457a51 100644 --- a/Classes/PHPExcel/Reader/Excel2007.php +++ b/Classes/PHPExcel/Reader/Excel2007.php @@ -1104,23 +1104,28 @@ class PHPExcel_Reader_Excel2007 implements PHPExcel_Reader_IReader $column = $autoFilter->getColumnByOffset((integer) $filterColumn["colId"]); if ($filterColumn->filters) { $filters = $filterColumn->filters; + // Standard filters are always an OR join foreach ($filters->filter as $filterRule) { - echo 'FILTER RULE',PHP_EOL; - echo (string) $filterRule["val"],PHP_EOL; - echo (string) $filterRule["operator"],PHP_EOL; + $column->createRule()->setRule( + (string) $filterRule["operator"], + (string) $filterRule["val"] + ); } } if ($filterColumn->customFilters) { $customFilters = $filterColumn->customFilters; - echo (string) $customFilters["and"],PHP_EOL; + // Custom filters can an AND or an OR join + if ((isset($customFilters["and"])) && ($customFilters["and"] == 1)) { + $column->setAndOr(PHPExcel_Worksheet_AutoFilter_Column::AUTOFILTER_COLUMN_ANDOR_AND); + } foreach ($customFilters->customFilter as $customFilterRule) { - echo 'CUSTOM FILTER RULE',PHP_EOL; - echo (string) $customFilterRule["val"],PHP_EOL; - echo (string) $customFilterRule["operator"],PHP_EOL; + $column->createRule()->setRule( + (string) $customFilterRule["operator"], + (string) $customFilterRule["val"] + ); } } } - var_dump($autoFilter); } if ($xmlSheet && $xmlSheet->mergeCells && $xmlSheet->mergeCells->mergeCell && !$this->_readDataOnly) { diff --git a/Classes/PHPExcel/Worksheet/AutoFilter.php b/Classes/PHPExcel/Worksheet/AutoFilter.php index 6620dde..ada60bb 100644 --- a/Classes/PHPExcel/Worksheet/AutoFilter.php +++ b/Classes/PHPExcel/Worksheet/AutoFilter.php @@ -192,6 +192,7 @@ class PHPExcel_Worksheet_AutoFilter if (!isset($this->_columns[$pColumn])) { $this->_columns[$pColumn] = new PHPExcel_Worksheet_AutoFilter_Column($pColumn, $this); } + return $this->_columns[$pColumn]; } @@ -206,12 +207,7 @@ class PHPExcel_Worksheet_AutoFilter list($rangeStart,$rangeEnd) = PHPExcel_Cell::rangeBoundaries($this->_range); $pColumn = PHPExcel_Cell::stringFromColumnIndex($rangeStart[0] + $pColumnOffset - 1); - echo 'Filter rules to apply for column ',$pColumn,PHP_EOL; - - if (!isset($this->_columns[$pColumn])) { - $this->_columns[$pColumn] = new PHPExcel_Worksheet_AutoFilter_Column($pColumn, $this); - } - return $this->_columns[$pColumn]; + return $this->getColumn($pColumn); } /** diff --git a/Classes/PHPExcel/Worksheet/AutoFilter/Column.php b/Classes/PHPExcel/Worksheet/AutoFilter/Column.php index 33ca3e0..1cfd474 100644 --- a/Classes/PHPExcel/Worksheet/AutoFilter/Column.php +++ b/Classes/PHPExcel/Worksheet/AutoFilter/Column.php @@ -172,7 +172,7 @@ class PHPExcel_Worksheet_AutoFilter_Column public function setAndOr($pAndOr = self::AUTOFILTER_COLUMN_ANDOR_OR) { // Lowercase And/Or $pAndOr = strtolower($pAndOr); - if (!in_array($pDataType,self::$_ruleConnections)) { + if (!in_array($pAndOr,self::$_ruleConnections)) { throw new PHPExcel_Exception('Invalid rule connection for column AutoFilter.'); } diff --git a/Classes/PHPExcel/Worksheet/AutoFilter/Column/Rule.php b/Classes/PHPExcel/Worksheet/AutoFilter/Column/Rule.php index fa0e01d..e44d922 100644 --- a/Classes/PHPExcel/Worksheet/AutoFilter/Column/Rule.php +++ b/Classes/PHPExcel/Worksheet/AutoFilter/Column/Rule.php @@ -43,16 +43,20 @@ class PHPExcel_Worksheet_AutoFilter_Column_Rule const AUTOFILTER_COLUMN_RULE_GREATERTHANOREQUAL = 'greaterThanOrEqual'; const AUTOFILTER_COLUMN_RULE_LESSTHAN = 'lessThan'; const AUTOFILTER_COLUMN_RULE_LESSTHANOREQUAL = 'lessThanOrEqual'; - /* Rule Operators (Numeric Special) which are translated to standard numeric operators with calculated values */ const AUTOFILTER_COLUMN_RULE_BETWEEN = 'between'; // greaterThanOrEqual 1 && lessThanOrEqual 2 + /* Rule Operators (Numeric Special) which are translated to standard numeric operators with calculated values */ const AUTOFILTER_COLUMN_RULE_TOPTEN = 'topTen'; // greaterThan calculated value const AUTOFILTER_COLUMN_RULE_TOPTENPERCENT = 'topTenPercent'; // greaterThan calculated value const AUTOFILTER_COLUMN_RULE_ABOVEAVERAGE = 'aboveAverage'; // Value is calculated as the average const AUTOFILTER_COLUMN_RULE_BELOWAVERAGE = 'belowAverage'; // Value is calculated as the average + /* Rule Operators (String) which are set as wild-carded values */ + const AUTOFILTER_COLUMN_RULE_BEGINSWITH = 'beginsWith'; // A* + const AUTOFILTER_COLUMN_RULE_ENDSWITH = 'endsWith'; // *Z + const AUTOFILTER_COLUMN_RULE_CONTAINS = 'contains'; // *B* + const AUTOFILTER_COLUMN_RULE_DOESNTCONTAIN = 'notEqual'; // notEqual *B* /* Rule Operators (Date Special) which are translated to standard numeric operators with calculated values */ const AUTOFILTER_COLUMN_RULE_BEFORE = 'lessThan'; const AUTOFILTER_COLUMN_RULE_AFTER = 'greaterThan'; - const AUTOFILTER_COLUMN_RULE_BETWEEN = 'between'; // greaterThanOrEqual 1 && lessThanOrEqual 2 const AUTOFILTER_COLUMN_RULE_YESTERDAY = 'yesterday'; const AUTOFILTER_COLUMN_RULE_TODAY = 'today'; const AUTOFILTER_COLUMN_RULE_TOMORROW = 'tomorrow'; @@ -71,11 +75,6 @@ class PHPExcel_Worksheet_AutoFilter_Column_Rule const AUTOFILTER_COLUMN_RULE_YEARTODATE = 'yearToDate'; // const AUTOFILTER_COLUMN_RULE_ALLDATESINMONTH = 'allDatesInMonth'; // for Month/February const AUTOFILTER_COLUMN_RULE_ALLDATESINQUARTER = 'allDatesInQuarter'; // for Quarter 2 - /* Rule Operators (String) which are set as wild-carded values */ - const AUTOFILTER_COLUMN_RULE_BEGINSWITH = 'beginsWith'; // A* - const AUTOFILTER_COLUMN_RULE_ENDSWITH = 'endsWith'; // *Z - const AUTOFILTER_COLUMN_RULE_CONTAINS = 'contains'; // *B* - const AUTOFILTER_COLUMN_RULE_DOESNTCONTAIN = 'notEqual'; // notEqual *B* /** * Autofilter Column @@ -147,6 +146,8 @@ class PHPExcel_Worksheet_AutoFilter_Column_Rule * @return PHPExcel_Worksheet_AutoFilter_Column_Rule */ public function setOperator($pOperator = self::AUTOFILTER_COLUMN_RULE_EQUAL) { + if (empty($pOperator)) + $pOperator = self::AUTOFILTER_COLUMN_RULE_EQUAL; $this->_operator = $pOperator; return $this; @@ -159,7 +160,7 @@ class PHPExcel_Worksheet_AutoFilter_Column_Rule * @throws Exception * @return PHPExcel_Worksheet_AutoFilter_Column_Rule */ - public function setRule($pOperator = self::AUTOFILTER_COLUMN_RULE_EQUAL, $pValue = '' { + public function setRule($pOperator = self::AUTOFILTER_COLUMN_RULE_EQUAL, $pValue = '') { $this->setOperator($pOperator); $this->setValue($pValue);