|
2 | 2 |
|
3 | 3 | namespace Yajra\DataTables\Jobs; |
4 | 4 |
|
5 | | -use OpenSpout\Common\Helper\CellTypeHelper; |
6 | | -use OpenSpout\Common\Type; |
7 | | -use OpenSpout\Writer\Common\Creator\Style\StyleBuilder; |
8 | | -use OpenSpout\Writer\Common\Creator\WriterEntityFactory; |
9 | 5 | use Carbon\Carbon; |
10 | 6 | use Illuminate\Bus\Batchable; |
11 | 7 | use Illuminate\Bus\Queueable; |
|
16 | 12 | use Illuminate\Queue\SerializesModels; |
17 | 13 | use Illuminate\Support\Arr; |
18 | 14 | use Illuminate\Support\Facades\Auth; |
19 | | -use Illuminate\Support\Facades\File; |
20 | 15 | use Illuminate\Support\Facades\Storage; |
21 | 16 | use Illuminate\Support\Str; |
| 17 | +use OpenSpout\Common\Helper\CellTypeHelper; |
| 18 | +use OpenSpout\Common\Type; |
| 19 | +use OpenSpout\Writer\Common\Creator\Style\StyleBuilder; |
| 20 | +use OpenSpout\Writer\Common\Creator\WriterEntityFactory; |
22 | 21 | use PhpOffice\PhpSpreadsheet\Shared\Date; |
23 | | -use Yajra\DataTables\Exceptions\Exception; |
24 | 22 | use Yajra\DataTables\Html\Column; |
25 | 23 | use Yajra\DataTables\Services\DataTable; |
26 | 24 |
|
@@ -113,13 +111,20 @@ public function handle() |
113 | 111 | WriterEntityFactory::createCell($date, (new StyleBuilder)->setFormat($format)->build()) |
114 | 112 | ); |
115 | 113 | } else { |
116 | | - $format = $column['exportFormat'] |
117 | | - ? (new StyleBuilder)->setFormat($column['exportFormat'])->build() |
118 | | - : null; |
119 | | - |
120 | | - $value = $this->isNumeric($value) ? (float) $value : $value; |
121 | | - |
122 | | - $cells->push(WriterEntityFactory::createCell($value, $format)); |
| 114 | + if ($this->wantsText($column)) { |
| 115 | + $cells->push( |
| 116 | + WriterEntityFactory::createCell($value, |
| 117 | + (new StyleBuilder)->setFormat($column['exportFormat'])->build()) |
| 118 | + ); |
| 119 | + } else { |
| 120 | + $format = $column['exportFormat'] |
| 121 | + ? (new StyleBuilder)->setFormat($column['exportFormat'])->build() |
| 122 | + : null; |
| 123 | + |
| 124 | + $value = $this->isNumeric($value) ? (float) $value : $value; |
| 125 | + |
| 126 | + $cells->push(WriterEntityFactory::createCell($value, $format)); |
| 127 | + } |
123 | 128 | } |
124 | 129 | }); |
125 | 130 |
|
@@ -154,4 +159,17 @@ protected function isNumeric($value): bool |
154 | 159 |
|
155 | 160 | return is_numeric($value); |
156 | 161 | } |
| 162 | + |
| 163 | + /** |
| 164 | + * @param \Yajra\DataTables\Html\Column $column |
| 165 | + * @return bool |
| 166 | + */ |
| 167 | + protected function wantsText(Column $column): bool |
| 168 | + { |
| 169 | + if (! isset($column['exportFormat'])) { |
| 170 | + return false; |
| 171 | + } |
| 172 | + |
| 173 | + return in_array($column['exportFormat'], config('datatables-export.text_formats', ['@'])); |
| 174 | + } |
157 | 175 | } |
0 commit comments