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 'bool':
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':
$rawValue = $formatter->format($rawValue, ['date', 'php:Y-m-d']);
break;
case 'datetime':
$rawValue = $formatter->format($rawValue, ['date', 'php:Y-m-d H:i:s']);
break;
case 'time':
$rawValue = $formatter->format($rawValue, ['date', 'php:H:i:s']);
break;
}
$options['data-raw-value'] = $rawValue;
} 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 . '"']);
}