kartik-v / yii2-grid

Enhanced GridView with various utilities for Yii Framework 2.0
http://demos.krajee.com/grid
Other
556 stars 303 forks source link

Bug with export excel auto format #982

Closed nsoloviev closed 3 years ago

nsoloviev commented 3 years ago

Prerequisites

Steps to reproduce the issue

  1. Set option: 'autoXlFormat' => true,
  2. Set column:
    'created_at' => [
    'attribute' => 'created_at',
    'value' => function ($model) {
        return date('d.m.Y H:i:s', strtotime($model->created_at));
    },
    'format' => 'datetime',
    ],
  3. Generates: <td class="w0" data-col-seq="created_at" data-raw-value="2021-01-08 16:13:24" style="mso-number-format: yyyy\-MM\-dd HH\:mm\:ss;">08.01.2021, 16:13:24</td>
  4. Export to Excel

Expected behavior and actual behavior

When I follow those steps, In the Excel file, the format remains the same as in the grid

I was expecting excel format

I debugged a little and realized that this condition is always false:

  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');
  }

https://github.com/kartik-v/yii2-grid/blob/master/src/assets/js/kv-grid-export.js#L376

Because $td.css('mso-number-format') is always undefined, I think because this is an unknown property

Browsers

Operating System

Libraries

Isolating the problem

stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.