mirror of
https://github.com/retailcrm/PHPExcel.git
synced 2024-11-26 23:36:03 +03:00
Support for AutoFilter active filters in the Excel2007 Reader
This commit is contained in:
parent
c9daa12245
commit
2251839f66
@ -1104,23 +1104,28 @@ class PHPExcel_Reader_Excel2007 implements PHPExcel_Reader_IReader
|
|||||||
$column = $autoFilter->getColumnByOffset((integer) $filterColumn["colId"]);
|
$column = $autoFilter->getColumnByOffset((integer) $filterColumn["colId"]);
|
||||||
if ($filterColumn->filters) {
|
if ($filterColumn->filters) {
|
||||||
$filters = $filterColumn->filters;
|
$filters = $filterColumn->filters;
|
||||||
|
// Standard filters are always an OR join
|
||||||
foreach ($filters->filter as $filterRule) {
|
foreach ($filters->filter as $filterRule) {
|
||||||
echo 'FILTER RULE',PHP_EOL;
|
$column->createRule()->setRule(
|
||||||
echo (string) $filterRule["val"],PHP_EOL;
|
(string) $filterRule["operator"],
|
||||||
echo (string) $filterRule["operator"],PHP_EOL;
|
(string) $filterRule["val"]
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ($filterColumn->customFilters) {
|
if ($filterColumn->customFilters) {
|
||||||
$customFilters = $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) {
|
foreach ($customFilters->customFilter as $customFilterRule) {
|
||||||
echo 'CUSTOM FILTER RULE',PHP_EOL;
|
$column->createRule()->setRule(
|
||||||
echo (string) $customFilterRule["val"],PHP_EOL;
|
(string) $customFilterRule["operator"],
|
||||||
echo (string) $customFilterRule["operator"],PHP_EOL;
|
(string) $customFilterRule["val"]
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var_dump($autoFilter);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($xmlSheet && $xmlSheet->mergeCells && $xmlSheet->mergeCells->mergeCell && !$this->_readDataOnly) {
|
if ($xmlSheet && $xmlSheet->mergeCells && $xmlSheet->mergeCells->mergeCell && !$this->_readDataOnly) {
|
||||||
|
@ -192,6 +192,7 @@ class PHPExcel_Worksheet_AutoFilter
|
|||||||
if (!isset($this->_columns[$pColumn])) {
|
if (!isset($this->_columns[$pColumn])) {
|
||||||
$this->_columns[$pColumn] = new PHPExcel_Worksheet_AutoFilter_Column($pColumn, $this);
|
$this->_columns[$pColumn] = new PHPExcel_Worksheet_AutoFilter_Column($pColumn, $this);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->_columns[$pColumn];
|
return $this->_columns[$pColumn];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -206,12 +207,7 @@ class PHPExcel_Worksheet_AutoFilter
|
|||||||
list($rangeStart,$rangeEnd) = PHPExcel_Cell::rangeBoundaries($this->_range);
|
list($rangeStart,$rangeEnd) = PHPExcel_Cell::rangeBoundaries($this->_range);
|
||||||
$pColumn = PHPExcel_Cell::stringFromColumnIndex($rangeStart[0] + $pColumnOffset - 1);
|
$pColumn = PHPExcel_Cell::stringFromColumnIndex($rangeStart[0] + $pColumnOffset - 1);
|
||||||
|
|
||||||
echo 'Filter rules to apply for column ',$pColumn,PHP_EOL;
|
return $this->getColumn($pColumn);
|
||||||
|
|
||||||
if (!isset($this->_columns[$pColumn])) {
|
|
||||||
$this->_columns[$pColumn] = new PHPExcel_Worksheet_AutoFilter_Column($pColumn, $this);
|
|
||||||
}
|
|
||||||
return $this->_columns[$pColumn];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -172,7 +172,7 @@ class PHPExcel_Worksheet_AutoFilter_Column
|
|||||||
public function setAndOr($pAndOr = self::AUTOFILTER_COLUMN_ANDOR_OR) {
|
public function setAndOr($pAndOr = self::AUTOFILTER_COLUMN_ANDOR_OR) {
|
||||||
// Lowercase And/Or
|
// Lowercase And/Or
|
||||||
$pAndOr = strtolower($pAndOr);
|
$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.');
|
throw new PHPExcel_Exception('Invalid rule connection for column AutoFilter.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,16 +43,20 @@ class PHPExcel_Worksheet_AutoFilter_Column_Rule
|
|||||||
const AUTOFILTER_COLUMN_RULE_GREATERTHANOREQUAL = 'greaterThanOrEqual';
|
const AUTOFILTER_COLUMN_RULE_GREATERTHANOREQUAL = 'greaterThanOrEqual';
|
||||||
const AUTOFILTER_COLUMN_RULE_LESSTHAN = 'lessThan';
|
const AUTOFILTER_COLUMN_RULE_LESSTHAN = 'lessThan';
|
||||||
const AUTOFILTER_COLUMN_RULE_LESSTHANOREQUAL = 'lessThanOrEqual';
|
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
|
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_TOPTEN = 'topTen'; // greaterThan calculated value
|
||||||
const AUTOFILTER_COLUMN_RULE_TOPTENPERCENT = 'topTenPercent'; // 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_ABOVEAVERAGE = 'aboveAverage'; // Value is calculated as the average
|
||||||
const AUTOFILTER_COLUMN_RULE_BELOWAVERAGE = 'belowAverage'; // 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 */
|
/* Rule Operators (Date Special) which are translated to standard numeric operators with calculated values */
|
||||||
const AUTOFILTER_COLUMN_RULE_BEFORE = 'lessThan';
|
const AUTOFILTER_COLUMN_RULE_BEFORE = 'lessThan';
|
||||||
const AUTOFILTER_COLUMN_RULE_AFTER = 'greaterThan';
|
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_YESTERDAY = 'yesterday';
|
||||||
const AUTOFILTER_COLUMN_RULE_TODAY = 'today';
|
const AUTOFILTER_COLUMN_RULE_TODAY = 'today';
|
||||||
const AUTOFILTER_COLUMN_RULE_TOMORROW = 'tomorrow';
|
const AUTOFILTER_COLUMN_RULE_TOMORROW = 'tomorrow';
|
||||||
@ -71,11 +75,6 @@ class PHPExcel_Worksheet_AutoFilter_Column_Rule
|
|||||||
const AUTOFILTER_COLUMN_RULE_YEARTODATE = 'yearToDate'; // <dynamicFilter val="40909" type="yearToDate" maxVal="41113"/>
|
const AUTOFILTER_COLUMN_RULE_YEARTODATE = 'yearToDate'; // <dynamicFilter val="40909" type="yearToDate" maxVal="41113"/>
|
||||||
const AUTOFILTER_COLUMN_RULE_ALLDATESINMONTH = 'allDatesInMonth'; // <dynamicFilter type="M2"/> for Month/February
|
const AUTOFILTER_COLUMN_RULE_ALLDATESINMONTH = 'allDatesInMonth'; // <dynamicFilter type="M2"/> for Month/February
|
||||||
const AUTOFILTER_COLUMN_RULE_ALLDATESINQUARTER = 'allDatesInQuarter'; // <dynamicFilter type="Q2"/> for Quarter 2
|
const AUTOFILTER_COLUMN_RULE_ALLDATESINQUARTER = 'allDatesInQuarter'; // <dynamicFilter type="Q2"/> 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
|
* Autofilter Column
|
||||||
@ -147,6 +146,8 @@ class PHPExcel_Worksheet_AutoFilter_Column_Rule
|
|||||||
* @return PHPExcel_Worksheet_AutoFilter_Column_Rule
|
* @return PHPExcel_Worksheet_AutoFilter_Column_Rule
|
||||||
*/
|
*/
|
||||||
public function setOperator($pOperator = self::AUTOFILTER_COLUMN_RULE_EQUAL) {
|
public function setOperator($pOperator = self::AUTOFILTER_COLUMN_RULE_EQUAL) {
|
||||||
|
if (empty($pOperator))
|
||||||
|
$pOperator = self::AUTOFILTER_COLUMN_RULE_EQUAL;
|
||||||
$this->_operator = $pOperator;
|
$this->_operator = $pOperator;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
@ -159,7 +160,7 @@ class PHPExcel_Worksheet_AutoFilter_Column_Rule
|
|||||||
* @throws Exception
|
* @throws Exception
|
||||||
* @return PHPExcel_Worksheet_AutoFilter_Column_Rule
|
* @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->setOperator($pOperator);
|
||||||
$this->setValue($pValue);
|
$this->setValue($pValue);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user