From 5e5229fd7ea30d65cdde15db073ea8cb1a39be68 Mon Sep 17 00:00:00 2001 From: Kartik Visweswaran Date: Wed, 15 Jul 2015 00:50:52 +0530 Subject: [PATCH] Upgrade to release v3.0.6 --- ActionColumn.php | 2 +- BooleanColumn.php | 2 +- CHANGE.md | 6 ++ CheckboxColumn.php | 2 +- CheckboxColumnAsset.php | 2 +- ColumnTrait.php | 95 ++++++++++++++++++++++++++++++- DataColumn.php | 9 ++- EditableColumn.php | 2 +- ExpandRowColumn.php | 2 +- ExpandRowColumnAsset.php | 2 +- FormulaColumn.php | 2 +- GridExportAsset.php | 2 +- GridFloatHeadAsset.php | 2 +- GridGroupAsset.php | 2 +- GridResizeColumnsAsset.php | 2 +- GridResizeStoreAsset.php | 2 +- GridView.php | 9 ++- GridViewAsset.php | 2 +- Module.php | 2 +- README.md | 3 +- RadioColumn.php | 2 +- RadioColumnAsset.php | 2 +- SerialColumn.php | 20 ++++++- assets/css/kv-grid-expand.css | 2 +- assets/css/kv-grid-expand.min.css | 2 +- assets/css/kv-grid.css | 2 +- assets/css/kv-grid.min.css | 2 +- assets/js/kv-grid-checkbox.js | 2 +- assets/js/kv-grid-checkbox.min.js | 2 +- assets/js/kv-grid-editable.js | 2 +- assets/js/kv-grid-editable.min.js | 2 +- assets/js/kv-grid-expand.js | 2 +- assets/js/kv-grid-expand.min.js | 2 +- assets/js/kv-grid-export.js | 14 +++-- assets/js/kv-grid-export.min.js | 4 +- assets/js/kv-grid-group.js | 2 +- assets/js/kv-grid-group.min.js | 2 +- assets/js/kv-grid-radio.js | 2 +- assets/js/kv-grid-radio.min.js | 2 +- controllers/ExportController.php | 4 +- 40 files changed, 180 insertions(+), 46 deletions(-) diff --git a/ActionColumn.php b/ActionColumn.php index 81bc1acd..44688a7e 100644 --- a/ActionColumn.php +++ b/ActionColumn.php @@ -3,7 +3,7 @@ /** * @copyright Copyright © Kartik Visweswaran, Krajee.com, 2014 - 2015 * @package yii2-grid - * @version 3.0.5 + * @version 3.0.6 */ namespace kartik\grid; diff --git a/BooleanColumn.php b/BooleanColumn.php index c08abed2..2b9308ec 100644 --- a/BooleanColumn.php +++ b/BooleanColumn.php @@ -4,7 +4,7 @@ * @package yii2-grid * @author Kartik Visweswaran * @copyright Copyright © Kartik Visweswaran, Krajee.com, 2014 - 2015 - * @version 3.0.5 + * @version 3.0.6 */ namespace kartik\grid; diff --git a/CHANGE.md b/CHANGE.md index 3fe1f3c8..38bd0e8a 100644 --- a/CHANGE.md +++ b/CHANGE.md @@ -1,3 +1,9 @@ +Version 3.0.6 +============= +**Date:** 15-Jul-2015 + +1. (enh #338): Various enhancements for grid excel export formatting. + Version 3.0.5 ============= **Date:** 07-Jul-2015 diff --git a/CheckboxColumn.php b/CheckboxColumn.php index 93eb024e..78d4ecab 100644 --- a/CheckboxColumn.php +++ b/CheckboxColumn.php @@ -4,7 +4,7 @@ * @package yii2-grid * @author Kartik Visweswaran * @copyright Copyright © Kartik Visweswaran, Krajee.com, 2014 - 2015 - * @version 3.0.5 + * @version 3.0.6 */ namespace kartik\grid; diff --git a/CheckboxColumnAsset.php b/CheckboxColumnAsset.php index e89caed3..a8130de5 100644 --- a/CheckboxColumnAsset.php +++ b/CheckboxColumnAsset.php @@ -4,7 +4,7 @@ * @package yii2-grid * @author Kartik Visweswaran * @copyright Copyright © Kartik Visweswaran, Krajee.com, 2014 - 2015 - * @version 3.0.5 + * @version 3.0.6 */ namespace kartik\grid; diff --git a/ColumnTrait.php b/ColumnTrait.php index 06cfd56b..76fc597e 100644 --- a/ColumnTrait.php +++ b/ColumnTrait.php @@ -4,7 +4,7 @@ * @package yii2-grid * @author Kartik Visweswaran * @copyright Copyright © Kartik Visweswaran, Krajee.com, 2014 - 2015 - * @version 3.0.5 + * @version 3.0.6 */ namespace kartik\grid; @@ -147,6 +147,99 @@ protected function checkValidFilters() } } + /** + * Gets Default Excel Cell Format + * + * @return string + */ + public function getDefaultExcelFormat() + { + if (!isset($this->format)) { + return ''; + } + + } + + /** + * Parses Excel Cell Formats for export + * + * @return string + */ + public function parseExcelFormats(&$options, $model, $key, $index) + { + $autoFormat = $this->grid->autoXlFormat; + if (!isset($this->xlsFormat) && !$autoFormat) { + return; + } + $fmt = ''; + $format = is_array($this->format) ? $this->format[0] : $this->format; + $formatter = $this->grid->formatter; + if (isset($this->xlFormat)) { + $fmt = $this->xlFormat; + } elseif ($autoFormat && isset($this->format)) { + $tSep = isset($formatter->thousandSeparator) ? $formatter->thousandSeparator : ','; + $dSep = isset($formatter->decimalSeparator) ? $formatter->decimalSeparator : '.'; + switch ($format) { + case 'text': + case 'html': + case 'raw': + case 'ntext': + case 'paragraphs': + case 'spellout': + case 'boolean': + case 'relativeTime': + $fmt = '\@'; + break; + case 'integer': + $fmt = "\\#\\{$tSep}\\#\\#0"; + break; + case 'decimal': + case 'percent': + case 'scientific': + $decimals = is_array($this->format) && isset($this->format[1]) ? $this->format[1] : 2; + $append = $decimals > 0 ? "\\{$dSep}" . str_repeat('0', $decimals) : ''; + if ($format == 'percent') { + $append .= '%'; + } + $fmt = ($format == 'scientific') ? "0{$append}E+00" : "\\#\\{$tSep}\\#\\#0" . $append; + break; + case 'currency': + $curr = is_array($this->format) && isset($this->format[1]) ? $this->format[1] : + isset($formatter->currencyCode) ? $formatter->currencyCode . ' ' : ''; + $fmt = "{$curr}\\#\\{$tSep}\\#\\#0{$dSep}00"; + break; + case 'date': + case 'time': + $fmt = 'Short ' . ucfirst($format); + break; + case 'datetime': + $fmt = 'yyyy\-MM\-dd HH\:mm\:ss'; + break; + default: + $fmt = ''; + break; + } + } + if ($format === 'date' || $format === 'datetime' || $format === 'time') { + $rawValue = $this->getDataCellValue($model, $key, $index); + switch ($format) { + case 'date': + $rawVal = $formatter->format($rawValue, ['date', 'php:Y-m-d']); + break; + case 'datetime': + $rawVal = $formatter->format($rawValue, ['date', 'php:Y-m-d H:i:s']); + break; + case 'time': + $rawVal = $formatter->format($rawValue, ['date', 'php:H:i:s']); + break; + } + $options['data-raw-value'] = $rawVal; + } elseif ($format === 'integer' || $format === 'decimal' || $format === 'percent' || $format === 'scientific') { + $options['data-raw-value'] = $this->getDataCellValue($model, $key, $index); + } + Html::addCssStyle($options, ['mso-number-format' => '"' . $fmt . '"']); + } + /** * Checks `hidden` property and hides the column from display * diff --git a/DataColumn.php b/DataColumn.php index a7cf49b2..f93daf19 100644 --- a/DataColumn.php +++ b/DataColumn.php @@ -4,7 +4,7 @@ * @package yii2-grid * @author Kartik Visweswaran * @copyright Copyright © Kartik Visweswaran, Krajee.com, 2014 - 2015 - * @version 3.0.5 + * @version 3.0.6 */ namespace kartik\grid; @@ -280,6 +280,12 @@ class DataColumn extends \yii\grid\DataColumn * - `options`: array, HTML attributes for the group footer row. */ public $groupFooter = []; + + /** + * @var string the cell format for EXCEL exported content. + * @see http://cosicimiento.blogspot.in/2008/11/styling-excel-cells-with-mso-number.html + */ + public $xlFormat; /** * @var array of row data for the column for the current page @@ -324,6 +330,7 @@ public function renderDataCell($model, $key, $index) { $options = $this->fetchContentOptions($model, $key, $index); $this->parseGrouping($options, $model, $key, $index); + $this->parseExcelFormats($options, $model, $key, $index); $this->initPjax($this->_clientScript); return Html::tag('td', $this->renderDataCellContent($model, $key, $index), $options); } diff --git a/EditableColumn.php b/EditableColumn.php index c1fa7560..15a4b1b3 100644 --- a/EditableColumn.php +++ b/EditableColumn.php @@ -4,7 +4,7 @@ * @package yii2-grid * @author Kartik Visweswaran * @copyright Copyright © Kartik Visweswaran, Krajee.com, 2014 - 2015 - * @version 3.0.5 + * @version 3.0.6 */ namespace kartik\grid; diff --git a/ExpandRowColumn.php b/ExpandRowColumn.php index 750a7938..d4abadf0 100644 --- a/ExpandRowColumn.php +++ b/ExpandRowColumn.php @@ -4,7 +4,7 @@ * @package yii2-grid * @author Kartik Visweswaran * @copyright Copyright © Kartik Visweswaran, Krajee.com, 2014 - 2015 - * @version 3.0.5 + * @version 3.0.6 */ namespace kartik\grid; diff --git a/ExpandRowColumnAsset.php b/ExpandRowColumnAsset.php index e262ccf0..b705fd75 100644 --- a/ExpandRowColumnAsset.php +++ b/ExpandRowColumnAsset.php @@ -4,7 +4,7 @@ * @package yii2-grid * @author Kartik Visweswaran * @copyright Copyright © Kartik Visweswaran, Krajee.com, 2014 - 2015 - * @version 3.0.5 + * @version 3.0.6 */ namespace kartik\grid; diff --git a/FormulaColumn.php b/FormulaColumn.php index 7a9867be..29dd1887 100644 --- a/FormulaColumn.php +++ b/FormulaColumn.php @@ -4,7 +4,7 @@ * @package yii2-grid * @author Kartik Visweswaran * @copyright Copyright © Kartik Visweswaran, Krajee.com, 2014 - 2015 - * @version 3.0.5 + * @version 3.0.6 */ namespace kartik\grid; diff --git a/GridExportAsset.php b/GridExportAsset.php index 75ccf592..9bd5b8d9 100644 --- a/GridExportAsset.php +++ b/GridExportAsset.php @@ -4,7 +4,7 @@ * @package yii2-grid * @author Kartik Visweswaran * @copyright Copyright © Kartik Visweswaran, Krajee.com, 2014 - 2015 - * @version 3.0.5 + * @version 3.0.6 */ namespace kartik\grid; diff --git a/GridFloatHeadAsset.php b/GridFloatHeadAsset.php index f748c323..8c2fc925 100644 --- a/GridFloatHeadAsset.php +++ b/GridFloatHeadAsset.php @@ -4,7 +4,7 @@ * @package yii2-grid * @author Kartik Visweswaran * @copyright Copyright © Kartik Visweswaran, Krajee.com, 2014 - 2015 - * @version 3.0.5 + * @version 3.0.6 */ namespace kartik\grid; diff --git a/GridGroupAsset.php b/GridGroupAsset.php index 4a2d94f5..5048f2ad 100644 --- a/GridGroupAsset.php +++ b/GridGroupAsset.php @@ -4,7 +4,7 @@ * @package yii2-grid * @author Kartik Visweswaran * @copyright Copyright © Kartik Visweswaran, Krajee.com, 2014 - 2015 - * @version 3.0.5 + * @version 3.0.6 */ namespace kartik\grid; diff --git a/GridResizeColumnsAsset.php b/GridResizeColumnsAsset.php index 14bca332..d950da97 100644 --- a/GridResizeColumnsAsset.php +++ b/GridResizeColumnsAsset.php @@ -4,7 +4,7 @@ * @package yii2-grid * @author Kartik Visweswaran * @copyright Copyright © Kartik Visweswaran, Krajee.com, 2014 - 2015 - * @version 3.0.5 + * @version 3.0.6 */ namespace kartik\grid; diff --git a/GridResizeStoreAsset.php b/GridResizeStoreAsset.php index eae4b1f3..af7e3084 100644 --- a/GridResizeStoreAsset.php +++ b/GridResizeStoreAsset.php @@ -4,7 +4,7 @@ * @package yii2-grid * @author Kartik Visweswaran * @copyright Copyright © Kartik Visweswaran, Krajee.com, 2014 - 2015 - * @version 3.0.5 + * @version 3.0.6 */ namespace kartik\grid; diff --git a/GridView.php b/GridView.php index 41629d32..b66a26db 100644 --- a/GridView.php +++ b/GridView.php @@ -4,7 +4,7 @@ * @package yii2-grid * @author Kartik Visweswaran * @copyright Copyright © Kartik Visweswaran, Krajee.com, 2014 - 2015 - * @version 3.0.5 + * @version 3.0.6 */ namespace kartik\grid; @@ -611,6 +611,13 @@ class GridView extends \yii\grid\GridView */ public $exportConversions = []; + /** + * @var boolean, applicable for EXCEL export content only. This determines whether the exported EXCEL cell data + * will be automatically guessed and formatted based on `DataColumn::format` property. You can override this + * behavior and change the auto-derived format mask by setting `DataColumn::xlFormat`. + */ + public $autoXlFormat = false; + /** * @var array|boolean the HTML attributes for the grid container. The grid table items * will be wrapped in a `div` container with the configured HTML attributes. The ID for diff --git a/GridViewAsset.php b/GridViewAsset.php index 0fb49e24..a30d10c0 100644 --- a/GridViewAsset.php +++ b/GridViewAsset.php @@ -4,7 +4,7 @@ * @package yii2-grid * @author Kartik Visweswaran * @copyright Copyright © Kartik Visweswaran, Krajee.com, 2014 - 2015 - * @version 3.0.5 + * @version 3.0.6 */ namespace kartik\grid; diff --git a/Module.php b/Module.php index ebcc543d..ff931f1b 100644 --- a/Module.php +++ b/Module.php @@ -4,7 +4,7 @@ * @package yii2-grid * @author Kartik Visweswaran * @copyright Copyright © Kartik Visweswaran, Krajee.com, 2014 - 2015 - * @version 3.0.5 + * @version 3.0.6 */ namespace kartik\grid; diff --git a/README.md b/README.md index 0370bf0f..bcbf224d 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ Refer [detailed documentation](http://demos.krajee.com/grid) and/or a [complete ![GridView Screenshot](https://lh4.googleusercontent.com/-4x-CdyyZAsY/VNxLPmaaAXI/AAAAAAAAAQ8/XYYxTiQZvJk/w868-h516-no/krajee-yii2-grid.jpg) ## Latest Release -The latest version of the module is v3.0.5. Refer the [CHANGE LOG](https://github.com/kartik-v/yii2-grid/blob/master/CHANGE.md) for details. +The latest version of the module is v3.0.6. Refer the [CHANGE LOG](https://github.com/kartik-v/yii2-grid/blob/master/CHANGE.md) for details. New features with release 2.7.0. @@ -33,6 +33,7 @@ New features with release 2.7.0. 5. Recursively replace/merge PDF export configuration correctly. 6. Include demo messages for auto generating via config. 7. Allows grouping grid column data, including master detail groups and generating group summaries (since v3.0.5). +8. Allows special formatting of data for cells exported in Excel Format. > NOTE: This extension depends on other yii2 extensions based on the functionality chosen by you. It will not install such dependent packages by default, but will prompt through an exception, if accessed. For example, if you choose to enable PDF export, then the [yii2-mpdf](http://demos.krajee.com/mpdf) will be mandatory and exception will be raised if `yii2-mpdf` is not installed. diff --git a/RadioColumn.php b/RadioColumn.php index e57b9911..38b2d380 100644 --- a/RadioColumn.php +++ b/RadioColumn.php @@ -4,7 +4,7 @@ * @package yii2-grid * @author Kartik Visweswaran * @copyright Copyright © Kartik Visweswaran, Krajee.com, 2014 - 2015 - * @version 3.0.5 + * @version 3.0.6 */ namespace kartik\grid; diff --git a/RadioColumnAsset.php b/RadioColumnAsset.php index 79c45304..2c8212b8 100644 --- a/RadioColumnAsset.php +++ b/RadioColumnAsset.php @@ -4,7 +4,7 @@ * @package yii2-grid * @author Kartik Visweswaran * @copyright Copyright © Kartik Visweswaran, Krajee.com, 2014 - 2015 - * @version 3.0.5 + * @version 3.0.6 */ namespace kartik\grid; diff --git a/SerialColumn.php b/SerialColumn.php index 54259242..c9793a8b 100644 --- a/SerialColumn.php +++ b/SerialColumn.php @@ -4,7 +4,7 @@ * @package yii2-grid * @author Kartik Visweswaran * @copyright Copyright © Kartik Visweswaran, Krajee.com, 2014 - 2015 - * @version 3.0.5 + * @version 3.0.6 */ namespace kartik\grid; @@ -98,6 +98,20 @@ class SerialColumn extends \yii\grid\SerialColumn */ public $mergeHeader = true; + /** + * @var string|array in which format should the value of each data model be displayed as (e.g. `"raw"`, `"text"`, `"html"`, + * `['date', 'php:Y-m-d']`). Supported formats are determined by the [[GridView::formatter|formatter]] used by + * the [[GridView]]. Default format is "text" which will format the value as an HTML-encoded plain text when + * [[\yii\i18n\Formatter]] is used as the [[GridView::$formatter|formatter]] of the GridView. + */ + public $format = 'text'; + + /** + * @var string the cell format for EXCEL exported content. + * @see http://cosicimiento.blogspot.in/2008/11/styling-excel-cells-with-mso-number.html + */ + public $xlFormat; + /** * @var array of row data for the column for the current page */ @@ -120,6 +134,8 @@ public function init() public function renderDataCell($model, $key, $index) { $options = $this->fetchContentOptions($model, $key, $index); - return Html::tag('td', $this->renderDataCellContent($model, $key, $index), $options); + $this->parseExcelFormats($options, $model, $key, $index); + $out = $this->grid->formatter->format($this->renderDataCellContent($model, $key, $index), $this->format); + return Html::tag('td', $out, $options); } } \ No newline at end of file diff --git a/assets/css/kv-grid-expand.css b/assets/css/kv-grid-expand.css index 4794c2a5..26fb692d 100644 --- a/assets/css/kv-grid-expand.css +++ b/assets/css/kv-grid-expand.css @@ -2,7 +2,7 @@ * @package yii2-grid * @author Kartik Visweswaran * @copyright Copyright © Kartik Visweswaran, Krajee.com, 2014 - 2015 - * @version 3.0.5 + * @version 3.0.6 * * Gridview ExpandRowColumn styling and enhancements * Built for Yii Framework 2.0 diff --git a/assets/css/kv-grid-expand.min.css b/assets/css/kv-grid-expand.min.css index 69aa8773..fcf0042a 100644 --- a/assets/css/kv-grid-expand.min.css +++ b/assets/css/kv-grid-expand.min.css @@ -2,7 +2,7 @@ * @package yii2-grid * @author Kartik Visweswaran * @copyright Copyright © Kartik Visweswaran, Krajee.com, 2014 - 2015 - * @version 3.0.5 + * @version 3.0.6 * * Gridview ExpandRowColumn styling and enhancements * Built for Yii Framework 2.0 diff --git a/assets/css/kv-grid.css b/assets/css/kv-grid.css index 6590e7bf..725ee542 100644 --- a/assets/css/kv-grid.css +++ b/assets/css/kv-grid.css @@ -2,7 +2,7 @@ * @package yii2-grid * @author Kartik Visweswaran * @copyright Copyright © Kartik Visweswaran, Krajee.com, 2014 - 2015 - * @version 3.0.5 + * @version 3.0.6 * * Gridview widget styling and enhancements for Bootstrap. * Built for Yii Framework 2.0 diff --git a/assets/css/kv-grid.min.css b/assets/css/kv-grid.min.css index fcf6b535..b518e70a 100644 --- a/assets/css/kv-grid.min.css +++ b/assets/css/kv-grid.min.css @@ -2,7 +2,7 @@ * @package yii2-grid * @author Kartik Visweswaran * @copyright Copyright © Kartik Visweswaran, Krajee.com, 2014 - 2015 - * @version 3.0.5 + * @version 3.0.6 * * Gridview widget styling and enhancements for Bootstrap. * Built for Yii Framework 2.0 diff --git a/assets/js/kv-grid-checkbox.js b/assets/js/kv-grid-checkbox.js index 6ca57190..8a2387f8 100644 --- a/assets/js/kv-grid-checkbox.js +++ b/assets/js/kv-grid-checkbox.js @@ -2,7 +2,7 @@ * @package yii2-grid * @author Kartik Visweswaran * @copyright Copyright © Kartik Visweswaran, Krajee.com, 2014 - 2015 - * @version 3.0.5 + * @version 3.0.6 * * Client actions for yii2-grid CheckboxColumn * diff --git a/assets/js/kv-grid-checkbox.min.js b/assets/js/kv-grid-checkbox.min.js index c5f16a93..427e377f 100644 --- a/assets/js/kv-grid-checkbox.min.js +++ b/assets/js/kv-grid-checkbox.min.js @@ -2,7 +2,7 @@ * @package yii2-grid * @author Kartik Visweswaran * @copyright Copyright © Kartik Visweswaran, Krajee.com, 2014 - 2015 - * @version 3.0.5 + * @version 3.0.6 * * Client actions for yii2-grid CheckboxColumn * diff --git a/assets/js/kv-grid-editable.js b/assets/js/kv-grid-editable.js index 3720a54c..a8ea82e4 100644 --- a/assets/js/kv-grid-editable.js +++ b/assets/js/kv-grid-editable.js @@ -2,7 +2,7 @@ * @package yii2-grid * @author Kartik Visweswaran * @copyright Copyright © Kartik Visweswaran, Krajee.com, 2014 - 2015 - * @version 3.0.5 + * @version 3.0.6 * * Client actions for yii2-grid EditableColumn * diff --git a/assets/js/kv-grid-editable.min.js b/assets/js/kv-grid-editable.min.js index 450a0f36..477e9343 100644 --- a/assets/js/kv-grid-editable.min.js +++ b/assets/js/kv-grid-editable.min.js @@ -2,7 +2,7 @@ * @package yii2-grid * @author Kartik Visweswaran * @copyright Copyright © Kartik Visweswaran, Krajee.com, 2014 - 2015 - * @version 3.0.5 + * @version 3.0.6 * * Client actions for yii2-grid EditableColumn * diff --git a/assets/js/kv-grid-expand.js b/assets/js/kv-grid-expand.js index dd0c38aa..c5aef1f8 100644 --- a/assets/js/kv-grid-expand.js +++ b/assets/js/kv-grid-expand.js @@ -2,7 +2,7 @@ * @package yii2-grid * @author Kartik Visweswaran * @copyright Copyright © Kartik Visweswaran, Krajee.com, 2014 - 2015 - * @version 3.0.5 + * @version 3.0.6 * * jQuery methods library for yii2-grid expand row column * diff --git a/assets/js/kv-grid-expand.min.js b/assets/js/kv-grid-expand.min.js index 56e2d9b1..320630d2 100644 --- a/assets/js/kv-grid-expand.min.js +++ b/assets/js/kv-grid-expand.min.js @@ -2,7 +2,7 @@ * @package yii2-grid * @author Kartik Visweswaran * @copyright Copyright © Kartik Visweswaran, Krajee.com, 2014 - 2015 - * @version 3.0.5 + * @version 3.0.6 * * Client actions for yii2-grid expand row * diff --git a/assets/js/kv-grid-export.js b/assets/js/kv-grid-export.js index f638d8bb..ca2b1a47 100644 --- a/assets/js/kv-grid-export.js +++ b/assets/js/kv-grid-export.js @@ -2,7 +2,7 @@ * @package yii2-grid * @author Kartik Visweswaran * @copyright Copyright © Kartik Visweswaran, Krajee.com, 2014 - 2015 - * @version 3.0.5 + * @version 3.0.6 * * Grid Export Validation Module for Yii's Gridview. Supports export of * grid data as CSV, HTML, or Excel. @@ -327,9 +327,15 @@ self.download('json', out); }, exportEXCEL: function () { - var self = this, $table = self.clean('xls'), cfg = self.config; - var css = (cfg.cssFile && self.config.cssFile.length) ? '' : ''; - var xls = templates.excel.replace('{encoding}', self.encoding).replace('{css}', css).replace('{worksheet}', + var self = this, $table = self.clean('xls'), cfg = self.config, xls, $td, + css = (cfg.cssFile && self.config.cssFile.length) ? '' : ''; + $table.find('td[data-raw-value]').each(function() { + $td = $(this); + if ($td.css('mso-number-format') || $td.css('mso-number-format') === 0 || $td.css('mso-number-format') === '0') { + $td.html($td.attr('data-raw-value')).removeAttr('data-raw-value'); + } + }); + xls = templates.excel.replace('{encoding}', self.encoding).replace('{css}', css).replace('{worksheet}', self.config.worksheet).replace('{data}', $('
').html($table).html()).replace(/"/g, '\''); self.download('xls', xls); } diff --git a/assets/js/kv-grid-export.min.js b/assets/js/kv-grid-export.min.js index 083ee6e5..8173e549 100644 --- a/assets/js/kv-grid-export.min.js +++ b/assets/js/kv-grid-export.min.js @@ -2,7 +2,7 @@ * @package yii2-grid * @author Kartik Visweswaran * @copyright Copyright © Kartik Visweswaran, Krajee.com, 2014 - 2015 - * @version 3.0.5 + * @version 3.0.6 * * Grid Export Validation Module for Yii's Gridview. Supports export of * grid data as CSV, HTML, or Excel. @@ -11,4 +11,4 @@ * Copyright: 2015, Kartik Visweswaran, Krajee.com * For more JQuery plugins visit http://plugins.krajee.com * For more Yii related demos visit http://demos.krajee.com - */!function(e){"use strict";var t=function(e,t,o){return e.split(t).join(o)},o=function(t,o){return null===t||void 0===t||0===t.length||o&&""===e.trim(t)},n=function(e,t,o,n){var i=screen.width/2-o/2,r=60,s=window.open("",t,"",!0);return s.close(),window.open(e,t,"toolbar=no, location=no, directories=no, status=yes, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width="+o+", height="+n+", top="+r+", left="+i)},i=function(e){return e.toLowerCase().replace(/[^\w ]+/g,"").replace(/ +/g,"-")},r={html:'{css}{data}',pdf:"{before}\n{data}\n{after}",excel:'{css}{data}',popup:'Grid Export - © Krajee{msg}'},s=function(t,o){this.$element=e(t);var n=o.gridOpts,i=o.genOpts;this.$grid=e("#"+n.gridId),this.messages=n.messages,this.target=n.target,this.exportConversions=n.exportConversions,this.showConfirmAlert=n.showConfirmAlert,this.filename=i.filename,this.showHeader=i.showHeader,this.showFooter=i.showFooter,this.showPageSummary=i.showPageSummary,this.$table=this.$grid.find(".kv-grid-table:first"),this.$form=this.$grid.find("form.kv-export-form"),this.encoding=this.$form.find('[name="export_encoding"]').val(),this.columns=this.showHeader?"td,th":"td",this.alertMsg=o.alertMsg,this.config=o.config,this.popup="",this.listen()};s.prototype={constructor:s,getArray:function(t){var n=this,r=n.clean(t),s=[],l={};return void 0!==n.config.colHeads&&n.config.colHeads.length>0?s=n.config.colHeads:r.find("thead tr th").each(function(t,r){var l=e(this).text().trim(),a=i(l);s[t]=!n.config.slugColHeads||o(a)?"col_"+t:a}),r.find('tbody tr:has("td")').each(function(t,o){l[t]={},e(this).children("td").each(function(o,n){var i=s[o];l[t][i]=e(this).text().trim()})}),l},notify:function(e){var t=this;if(!t.showConfirmAlert)return e.preventDefault(),!0;var n=t.messages,i=o(t.alertMsg)?"":t.alertMsg,r=o(n.allowPopups)?"":n.allowPopups,s=o(n.confirmDownload)?"":n.confirmDownload,l="";return l=i.length&&r.length?i+"\n\n"+r:!i.length&&r.length?r:i.length&&!r.length?i:"",s.length&&(l=l+"\n\n"+s),e.preventDefault(),o(l)?!0:t.kvConfirm(l)},kvConfirm:function(e){try{return window.confirm(e)}catch(t){return!0}},setPopupAlert:function(e){var t=this;if(void 0!==t.popup.document)if(arguments.length&&arguments[1]){var o=t.popup.document.getElementsByTagName("body");setTimeout(function(){o[0].innerHTML=e},4e3)}else{var n=r.popup.replace("{msg}",e);t.popup.document.write(n)}},listenClick:function(e){var t=this,n=arguments.length>1?arguments[1]:"";t.$element.on("click",function(i){t.notify(i)&&(o(n)?t[e]():t[e](n),i.preventDefault())})},listen:function(){var e=this;"_popup"===e.target&&e.$form.on("submit",function(){setTimeout(function(){e.setPopupAlert(e.messages.downloadComplete,!0)},1e3)}),e.$element.hasClass("export-csv")&&e.listenClick("exportTEXT","csv"),e.$element.hasClass("export-txt")&&e.listenClick("exportTEXT","txt"),e.$element.hasClass("export-html")&&e.listenClick("exportHTML"),e.$element.hasClass("export-xls")&&e.listenClick("exportEXCEL"),e.$element.hasClass("export-json")&&e.listenClick("exportJSON"),e.$element.hasClass("export-pdf")&&e.listenClick("exportPDF")},clean:function(t){var o=this,n=o.$table.clone();n.find("tr.filters").remove(),n.find("th").removeAttr("rowspan"),n.find("th").find("a").each(function(){e(this).contents().unwrap()}),n.find("input").remove(),o.showHeader||n.find("thead").remove(),o.showPageSummary||n.find("tfoot.kv-page-summary").remove(),o.showFooter||n.find("tfoot.kv-table-footer").remove(),o.showCaption||n.find("kv-table-caption").remove(),n.find(".skip-export").remove(),n.find(".skip-export-"+t).remove();var i=n.html();return i=o.preProcess(i),n.html(i),n},preProcess:function(e){var o,n=this,i=n.exportConversions,r=i.length,s=e;if(r>0)for(var l=0;r>l;l++)o=i[l],s=t(s,o.from,o.to);return s},download:function(e,t){var i=this,r=i.$element.data("format"),s=o(i.config)?{}:i.config;i.$form.find('[name="export_filetype"]').val(e),i.$form.find('[name="export_filename"]').val(i.filename),i.$form.find('[name="export_content"]').val(t),i.$form.find('[name="export_mime"]').val(r),i.$form.find('[name="export_config"]').val("pdf"===e?JSON.stringify(s):""),"_popup"===i.target&&(i.popup=n("","kvDownloadDialog",350,120),i.popup.focus(),i.setPopupAlert(i.messages.downloadProgress)),i.$form.submit()},exportHTML:function(){var t=this,o=t.clean("html"),n=t.config,i=t.config.cssFile&&n.cssFile.length?'':"",s=r.html.replace("{encoding}",t.encoding).replace("{css}",i).replace("{data}",e("
").html(o).html());t.download("html",s)},exportPDF:function(){var t=this,n=t.clean("pdf"),i=o(t.config.contentBefore)?"":t.config.contentBefore,s=o(t.config.contentAfter)?"":t.config.contentAfter,l=t.config.css,a=r.pdf.replace("{css}",l).replace("{before}",i).replace("{after}",s).replace("{data}",e("
").html(n).html());t.download("pdf",a)},exportTEXT:function(t){var o=this,n=o.clean(t),i=n.find("tr:has("+o.columns+")"),r=String.fromCharCode(11),s=String.fromCharCode(0),l='"'+o.config.colDelimiter+'"',a='"'+o.config.rowDelimiter+'"',c='"'+i.map(function(t,n){var i=e(n),s=i.find(o.columns);return s.map(function(t,o){var n=e(o),i=n.text().trim();return i.replace('"','""')}).get().join(r)}).get().join(s).split(s).join(a).split(r).join(l)+'"';o.download(t,c)},exportJSON:function(){var e=this,t=e.getArray("json");t=JSON.stringify(t,e.config.jsonReplacer,e.config.indentSpace),e.download("json",t)},exportEXCEL:function(){var t=this,o=t.clean("xls"),n=t.config,i=n.cssFile&&t.config.cssFile.length?'':"",s=r.excel.replace("{encoding}",t.encoding).replace("{css}",i).replace("{worksheet}",t.config.worksheet).replace("{data}",e("
").html(o).html()).replace(/"/g,"'");t.download("xls",s)}},e.fn.gridexport=function(t){var o=Array.apply(null,arguments);return o.shift(),this.each(function(){var n=e(this),i=n.data("gridexport"),r="object"==typeof t&&t;i||n.data("gridexport",i=new s(this,e.extend({},e.fn.gridexport.defaults,r,e(this).data()))),"string"==typeof t&&i[t].apply(i,o)})},e.fn.gridexport.defaults={},e.fn.gridexport.Constructor=s}(window.jQuery); \ No newline at end of file + */!function(e){"use strict";var t=function(e,t,o){return e.split(t).join(o)},o=function(t,o){return null===t||void 0===t||0===t.length||o&&""===e.trim(t)},n=function(e,t,o,n){var i=screen.width/2-o/2,r=60,s=window.open("",t,"",!0);return s.close(),window.open(e,t,"toolbar=no, location=no, directories=no, status=yes, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width="+o+", height="+n+", top="+r+", left="+i)},i=function(e){return e.toLowerCase().replace(/[^\w ]+/g,"").replace(/ +/g,"-")},r={html:'{css}{data}',pdf:"{before}\n{data}\n{after}",excel:'{css}{data}',popup:'Grid Export - © Krajee{msg}'},s=function(t,o){this.$element=e(t);var n=o.gridOpts,i=o.genOpts;this.$grid=e("#"+n.gridId),this.messages=n.messages,this.target=n.target,this.exportConversions=n.exportConversions,this.showConfirmAlert=n.showConfirmAlert,this.filename=i.filename,this.showHeader=i.showHeader,this.showFooter=i.showFooter,this.showPageSummary=i.showPageSummary,this.$table=this.$grid.find(".kv-grid-table:first"),this.$form=this.$grid.find("form.kv-export-form"),this.encoding=this.$form.find('[name="export_encoding"]').val(),this.columns=this.showHeader?"td,th":"td",this.alertMsg=o.alertMsg,this.config=o.config,this.popup="",this.listen()};s.prototype={constructor:s,getArray:function(t){var n=this,r=n.clean(t),s=[],a={};return void 0!==n.config.colHeads&&n.config.colHeads.length>0?s=n.config.colHeads:r.find("thead tr th").each(function(t,r){var a=e(this).text().trim(),l=i(a);s[t]=!n.config.slugColHeads||o(l)?"col_"+t:l}),r.find('tbody tr:has("td")').each(function(t,o){a[t]={},e(this).children("td").each(function(o,n){var i=s[o];a[t][i]=e(this).text().trim()})}),a},notify:function(e){var t=this;if(!t.showConfirmAlert)return e.preventDefault(),!0;var n=t.messages,i=o(t.alertMsg)?"":t.alertMsg,r=o(n.allowPopups)?"":n.allowPopups,s=o(n.confirmDownload)?"":n.confirmDownload,a="";return a=i.length&&r.length?i+"\n\n"+r:!i.length&&r.length?r:i.length&&!r.length?i:"",s.length&&(a=a+"\n\n"+s),e.preventDefault(),o(a)?!0:t.kvConfirm(a)},kvConfirm:function(e){try{return window.confirm(e)}catch(t){return!0}},setPopupAlert:function(e){var t=this;if(void 0!==t.popup.document)if(arguments.length&&arguments[1]){var o=t.popup.document.getElementsByTagName("body");setTimeout(function(){o[0].innerHTML=e},4e3)}else{var n=r.popup.replace("{msg}",e);t.popup.document.write(n)}},listenClick:function(e){var t=this,n=arguments.length>1?arguments[1]:"";t.$element.on("click",function(i){t.notify(i)&&(o(n)?t[e]():t[e](n),i.preventDefault())})},listen:function(){var e=this;"_popup"===e.target&&e.$form.on("submit",function(){setTimeout(function(){e.setPopupAlert(e.messages.downloadComplete,!0)},1e3)}),e.$element.hasClass("export-csv")&&e.listenClick("exportTEXT","csv"),e.$element.hasClass("export-txt")&&e.listenClick("exportTEXT","txt"),e.$element.hasClass("export-html")&&e.listenClick("exportHTML"),e.$element.hasClass("export-xls")&&e.listenClick("exportEXCEL"),e.$element.hasClass("export-json")&&e.listenClick("exportJSON"),e.$element.hasClass("export-pdf")&&e.listenClick("exportPDF")},clean:function(t){var o=this,n=o.$table.clone();n.find("tr.filters").remove(),n.find("th").removeAttr("rowspan"),n.find("th").find("a").each(function(){e(this).contents().unwrap()}),n.find("input").remove(),o.showHeader||n.find("thead").remove(),o.showPageSummary||n.find("tfoot.kv-page-summary").remove(),o.showFooter||n.find("tfoot.kv-table-footer").remove(),o.showCaption||n.find("kv-table-caption").remove(),n.find(".skip-export").remove(),n.find(".skip-export-"+t).remove();var i=n.html();return i=o.preProcess(i),n.html(i),n},preProcess:function(e){var o,n=this,i=n.exportConversions,r=i.length,s=e;if(r>0)for(var a=0;r>a;a++)o=i[a],s=t(s,o.from,o.to);return s},download:function(e,t){var i=this,r=i.$element.data("format"),s=o(i.config)?{}:i.config;i.$form.find('[name="export_filetype"]').val(e),i.$form.find('[name="export_filename"]').val(i.filename),i.$form.find('[name="export_content"]').val(t),i.$form.find('[name="export_mime"]').val(r),i.$form.find('[name="export_config"]').val("pdf"===e?JSON.stringify(s):""),"_popup"===i.target&&(i.popup=n("","kvDownloadDialog",350,120),i.popup.focus(),i.setPopupAlert(i.messages.downloadProgress)),i.$form.submit()},exportHTML:function(){var t=this,o=t.clean("html"),n=t.config,i=t.config.cssFile&&n.cssFile.length?'':"",s=r.html.replace("{encoding}",t.encoding).replace("{css}",i).replace("{data}",e("
").html(o).html());t.download("html",s)},exportPDF:function(){var t=this,n=t.clean("pdf"),i=o(t.config.contentBefore)?"":t.config.contentBefore,s=o(t.config.contentAfter)?"":t.config.contentAfter,a=t.config.css,l=r.pdf.replace("{css}",a).replace("{before}",i).replace("{after}",s).replace("{data}",e("
").html(n).html());t.download("pdf",l)},exportTEXT:function(t){var o=this,n=o.clean(t),i=n.find("tr:has("+o.columns+")"),r=String.fromCharCode(11),s=String.fromCharCode(0),a='"'+o.config.colDelimiter+'"',l='"'+o.config.rowDelimiter+'"',c='"'+i.map(function(t,n){var i=e(n),s=i.find(o.columns);return s.map(function(t,o){var n=e(o),i=n.text().trim();return i.replace('"','""')}).get().join(r)}).get().join(s).split(s).join(l).split(r).join(a)+'"';o.download(t,c)},exportJSON:function(){var e=this,t=e.getArray("json");t=JSON.stringify(t,e.config.jsonReplacer,e.config.indentSpace),e.download("json",t)},exportEXCEL:function(){var t,o,n=this,i=n.clean("xls"),s=n.config,a=s.cssFile&&n.config.cssFile.length?'':"";i.find("td[data-raw-value]").each(function(){o=e(this),(o.css("mso-number-format")||0===o.css("mso-number-format")||"0"===o.css("mso-number-format"))&&o.html(o.attr("data-raw-value")).removeAttr("data-raw-value")}),t=r.excel.replace("{encoding}",n.encoding).replace("{css}",a).replace("{worksheet}",n.config.worksheet).replace("{data}",e("
").html(i).html()).replace(/"/g,"'"),n.download("xls",t)}},e.fn.gridexport=function(t){var o=Array.apply(null,arguments);return o.shift(),this.each(function(){var n=e(this),i=n.data("gridexport"),r="object"==typeof t&&t;i||n.data("gridexport",i=new s(this,e.extend({},e.fn.gridexport.defaults,r,e(this).data()))),"string"==typeof t&&i[t].apply(i,o)})},e.fn.gridexport.defaults={},e.fn.gridexport.Constructor=s}(window.jQuery); \ No newline at end of file diff --git a/assets/js/kv-grid-group.js b/assets/js/kv-grid-group.js index 5ca54bd4..364141f8 100644 --- a/assets/js/kv-grid-group.js +++ b/assets/js/kv-grid-group.js @@ -2,7 +2,7 @@ * @package yii2-grid * @author Kartik Visweswaran * @copyright Copyright © Kartik Visweswaran, Krajee.com, 2014 - 2015 - * @version 3.0.5 + * @version 3.0.6 * * Grid grouping jquery library created for yii2-grid. * diff --git a/assets/js/kv-grid-group.min.js b/assets/js/kv-grid-group.min.js index 77c19eeb..3085e2d9 100644 --- a/assets/js/kv-grid-group.min.js +++ b/assets/js/kv-grid-group.min.js @@ -2,7 +2,7 @@ * @package yii2-grid * @author Kartik Visweswaran * @copyright Copyright © Kartik Visweswaran, Krajee.com, 2014 - 2015 - * @version 3.0.5 + * @version 3.0.6 * * Grid grouping jquery library created for yii2-grid. * diff --git a/assets/js/kv-grid-radio.js b/assets/js/kv-grid-radio.js index c3c19c86..2b8ffa89 100644 --- a/assets/js/kv-grid-radio.js +++ b/assets/js/kv-grid-radio.js @@ -2,7 +2,7 @@ * @package yii2-grid * @author Kartik Visweswaran * @copyright Copyright © Kartik Visweswaran, Krajee.com, 2014 - 2015 - * @version 3.0.5 + * @version 3.0.6 * * Client actions for yii2-grid RadioColumn * diff --git a/assets/js/kv-grid-radio.min.js b/assets/js/kv-grid-radio.min.js index a74b2682..9f40a737 100644 --- a/assets/js/kv-grid-radio.min.js +++ b/assets/js/kv-grid-radio.min.js @@ -2,7 +2,7 @@ * @package yii2-grid * @author Kartik Visweswaran * @copyright Copyright © Kartik Visweswaran, Krajee.com, 2014 - 2015 - * @version 3.0.5 + * @version 3.0.6 * * Client actions for yii2-grid RadioColumn * diff --git a/controllers/ExportController.php b/controllers/ExportController.php index b0cbb2d5..92a31c24 100644 --- a/controllers/ExportController.php +++ b/controllers/ExportController.php @@ -4,7 +4,7 @@ * @package yii2-grid * @author Kartik Visweswaran * @copyright Copyright © Kartik Visweswaran, Krajee.com, 2014 - 2015 - * @version 3.0.5 + * @version 3.0.6 */ namespace kartik\grid\controllers; @@ -37,8 +37,6 @@ public function actionDownload() $config = Json::decode($config); $this->generatePDF($content, "{$name}.pdf", $config); return; - } elseif ($type == GridView::EXCEL) { - $content = str_replace('', '‌', $content); } $this->setHttpHeaders($type, $name, $mime, $encoding); return $content;