diff --git a/CHANGE.md b/CHANGE.md index 874e534..503831b 100755 --- a/CHANGE.md +++ b/CHANGE.md @@ -3,8 +3,9 @@ Change Log: `yii2-export` ## version 1.2.8 -**Date:** 21-Jun-2017 +**Date:** 19-Nov-2017 +- (bug #221, #222): Correct auto filter. - (bug #211): Correct directory creation to be recursive. - (enh #209): New event property `onGenerateFile`. - (enh #208): Optimize code and eliminate redundant properties. @@ -15,6 +16,7 @@ Change Log: `yii2-export` - Code documentation enhancements. - (enh #188): Better validation of empty data using `isset`. - (enh #185): Add Vietnamese Translations. +- (enh #126): Allow HTML tags in cell value based on data column format. ## version 1.2.7 diff --git a/ExportMenu.php b/ExportMenu.php index 735b598..a22fe56 100755 --- a/ExportMenu.php +++ b/ExportMenu.php @@ -576,7 +576,7 @@ class ExportMenu extends GridView /** * @var integer the current table end row */ - protected $_endRow = 1; + protected $_endRow = 0; /** * @var integer the current table end column @@ -1173,12 +1173,12 @@ public function generateBody() } // Set autofilter on - $this->_objPHPExcelSheet->setAutoFilter( - self::columnName(1) . $this->_beginRow . ':' . self::columnName($this->_endCol) . $this->_endRow - ); + $from = self::columnName(1) . $this->_beginRow; + $to = self::columnName($this->_endCol) . ($this->_endRow + $this->_beginRow); + $this->_objPHPExcelSheet->setAutoFilter("{$from}:{$to}"); return $this->_endRow; } - + /** * Generates an output data row with the given data model and key. * @@ -1193,12 +1193,12 @@ public function generateRow($model, $key, $index) */ $this->_endCol = 0; foreach ($this->getVisibleColumns() as $column) { + $format = $this->enableFormatter && isset($column->format) ? $column->format : 'raw'; if ($column instanceof SerialColumn) { $value = $column->renderDataCell($model, $key, $index); } elseif ($column instanceof ActionColumn) { $value = null; } elseif (!isset($column->content)) { - $format = $this->enableFormatter && isset($column->format) ? $column->format : 'raw'; $value = method_exists($column, 'getDataCellValue') ? $this->formatter->format($column->getDataCellValue($model, $key, $index), $format) : $column->renderDataCell($model, $key, $index); @@ -1210,9 +1210,18 @@ public function generateRow($model, $key, $index) $value = null; } $this->_endCol++; + if (isset($value) && $value !== '') { + $f = is_array($format) ? (isset($format[0]) ? $format[0] : 'raw') : + ($format instanceof Closure ? 'raw' : $format); + if ($f !== 'raw' && $f !== 'html' && $f !== 'text') { + $value = strip_tags($value); + } + } else { + $value = ''; + } $cell = $this->_objPHPExcelSheet->setCellValue( self::columnName($this->_endCol) . ($index + $this->_beginRow + 1), - !isset($value) || $value === '' ? '' : strip_tags($value), + $value, true ); $this->raiseEvent('onRenderDataCell', [$cell, $value, $model, $key, $index, $this]);