Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 31 additions & 13 deletions src/Jobs/DataTableExportJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@

namespace Yajra\DataTables\Jobs;

use OpenSpout\Common\Helper\CellTypeHelper;
use OpenSpout\Common\Type;
use OpenSpout\Writer\Common\Creator\Style\StyleBuilder;
use OpenSpout\Writer\Common\Creator\WriterEntityFactory;
use Carbon\Carbon;
use Illuminate\Bus\Batchable;
use Illuminate\Bus\Queueable;
Expand All @@ -16,11 +12,13 @@
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Str;
use OpenSpout\Common\Helper\CellTypeHelper;
use OpenSpout\Common\Type;
use OpenSpout\Writer\Common\Creator\Style\StyleBuilder;
use OpenSpout\Writer\Common\Creator\WriterEntityFactory;
use PhpOffice\PhpSpreadsheet\Shared\Date;
use Yajra\DataTables\Exceptions\Exception;
use Yajra\DataTables\Html\Column;
use Yajra\DataTables\Services\DataTable;

Expand Down Expand Up @@ -113,13 +111,20 @@ public function handle()
WriterEntityFactory::createCell($date, (new StyleBuilder)->setFormat($format)->build())
);
} else {
$format = $column['exportFormat']
? (new StyleBuilder)->setFormat($column['exportFormat'])->build()
: null;

$value = $this->isNumeric($value) ? (float) $value : $value;

$cells->push(WriterEntityFactory::createCell($value, $format));
if ($this->wantsText($column)) {
$cells->push(
WriterEntityFactory::createCell($value,
(new StyleBuilder)->setFormat($column['exportFormat'])->build())
);
} else {
$format = $column['exportFormat']
? (new StyleBuilder)->setFormat($column['exportFormat'])->build()
: null;

$value = $this->isNumeric($value) ? (float) $value : $value;

$cells->push(WriterEntityFactory::createCell($value, $format));
}
}
});

Expand Down Expand Up @@ -154,4 +159,17 @@ protected function isNumeric($value): bool

return is_numeric($value);
}

/**
* @param \Yajra\DataTables\Html\Column $column
* @return bool
*/
protected function wantsText(Column $column): bool
{
if (! isset($column['exportFormat'])) {
return false;
}

return in_array($column['exportFormat'], config('datatables-export.text_formats', []));
}
}
14 changes: 14 additions & 0 deletions src/config/datatables-export.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,20 @@
NumberFormat::FORMAT_DATE_YYYYMMDDSLASH,
],

/*
|--------------------------------------------------------------------------
| Valid Text Formats
|--------------------------------------------------------------------------
|
| List of valid text formats to be used.
|
*/
'text_formats' => [
'@',
NumberFormat::FORMAT_GENERAL,
NumberFormat::FORMAT_TEXT
],

/*
|--------------------------------------------------------------------------
| Purge Options
Expand Down