Skip to content

Commit 2975a29

Browse files
committed
feat: [bc] openspout v4
1 parent 26c6c5a commit 2975a29

File tree

2 files changed

+32
-31
lines changed

2 files changed

+32
-31
lines changed

composer.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@
1818
],
1919
"require": {
2020
"php": ">=7.4|8.*",
21-
"yajra/laravel-datatables-buttons": "4.*|9.*|10.*",
22-
"livewire/livewire": "2.*|3.*",
23-
"openspout/openspout": "^3",
24-
"ext-json": "*"
21+
"ext-json": "*",
22+
"livewire/livewire": "^2.11.2",
23+
"openspout/openspout": "^4.12.1",
24+
"phpoffice/phpspreadsheet": "^1.27",
25+
"yajra/laravel-datatables-buttons": "10.*"
2526
},
2627
"require-dev": {
27-
"maatwebsite/excel": "^3.1.47",
28-
"nunomaduro/larastan": "^1.0|^2.4.1",
29-
"orchestra/testbench": "6.*|^7.3|8.*"
28+
"nunomaduro/larastan": "^2.4.1",
29+
"orchestra/testbench": "^8.0.1"
3030
},
3131
"autoload": {
3232
"psr-4": {
@@ -45,7 +45,7 @@
4545
},
4646
"extra": {
4747
"branch-alias": {
48-
"dev-master": "1.0-dev"
48+
"dev-master": "2.0-dev"
4949
},
5050
"laravel": {
5151
"providers": [

src/Jobs/DataTableExportJob.php

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Yajra\DataTables\Jobs;
44

55
use Carbon\Carbon;
6+
use DateTimeInterface;
67
use Illuminate\Auth\Events\Login;
78
use Illuminate\Bus\Batchable;
89
use Illuminate\Bus\Queueable;
@@ -20,12 +21,12 @@
2021
use Illuminate\Support\Facades\Mail;
2122
use Illuminate\Support\Facades\Storage;
2223
use Illuminate\Support\Str;
23-
use OpenSpout\Common\Helper\CellTypeHelper;
24-
use OpenSpout\Common\Type;
25-
use OpenSpout\Writer\Common\Creator\Style\StyleBuilder;
26-
use OpenSpout\Writer\Common\Creator\WriterEntityFactory;
24+
use OpenSpout\Common\Entity\Cell;
25+
use OpenSpout\Common\Entity\Row;
26+
use OpenSpout\Common\Entity\Style\Style;
27+
use OpenSpout\Writer\Common\Creator\WriterFactory;
28+
use OpenSpout\Writer\XLSX\Helper\DateHelper;
2729
use OpenSpout\Writer\XLSX\Writer as XLSXWriter;
28-
use PhpOffice\PhpSpreadsheet\Shared\Date;
2930
use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
3031
use Yajra\DataTables\Html\Column;
3132
use Yajra\DataTables\Services\DataTable;
@@ -95,14 +96,14 @@ public function handle()
9596
$dataTable = app()->call([$oTable, 'dataTable'], compact('query'));
9697
$dataTable->skipPaging();
9798

98-
$exportType = strval(request('exportType'));
99+
$exportType = strtolower(strval(request('exportType')));
99100

100-
$type = Str::startsWith($exportType, Type::CSV) ? Type::CSV : Type::XLSX;
101+
$type = Str::startsWith($exportType, 'csv') ? 'csv' : 'xlsx';
101102
$filename = $this->batchId.'.'.$type;
102103

103104
$path = Storage::disk($this->getDisk())->path($filename);
104105

105-
$writer = WriterEntityFactory::createWriter($type);
106+
$writer = WriterFactory::createFromFile($filename);
106107
$writer->openToFile($path);
107108

108109
if ($writer instanceof XLSXWriter) {
@@ -113,7 +114,7 @@ public function handle()
113114

114115
$columns = $this->getExportableColumns($oTable);
115116
$writer->addRow(
116-
WriterEntityFactory::createRowFromArray(
117+
Row::fromValues(
117118
$columns->map(fn (Column $column) => strip_tags($column->title))->toArray()
118119
)
119120
);
@@ -157,14 +158,14 @@ public function handle()
157158
$format = $column->exportFormat ?? '@';
158159
break;
159160
case $this->wantsDateFormat($column):
160-
$cellValue = $value ? Date::dateTimeToExcel(Carbon::parse(strval($value))) : '';
161+
$cellValue = $value ? DateHelper::toExcel(Carbon::parse(strval($value))) : '';
161162
$format = $column->exportFormat ?? $defaultDateFormat;
162163
break;
163164
case $this->wantsNumeric($column):
164165
$cellValue = floatval($value);
165166
$format = $column->exportFormat;
166167
break;
167-
case CellTypeHelper::isDateTimeOrDateInterval($value):
168+
case $value instanceof DateTimeInterface:
168169
$cellValue = $value;
169170
$format = $column->exportFormat ?? $defaultDateFormat;
170171
break;
@@ -173,10 +174,10 @@ public function handle()
173174
$format = $column->exportFormat ?? NumberFormat::FORMAT_GENERAL;
174175
}
175176

176-
$cells[] = WriterEntityFactory::createCell($cellValue, (new StyleBuilder)->setFormat($format)->build());
177+
$cells[] = Cell::fromValue($cellValue, (new Style)->setFormat($format));
177178
});
178179

179-
$writer->addRow(WriterEntityFactory::createRow($cells));
180+
$writer->addRow(new Row($cells));
180181
}
181182

182183
$writer->close();
@@ -199,14 +200,6 @@ protected function getDisk(): string
199200
return strval(config('datatables-export.disk', 'local'));
200201
}
201202

202-
/**
203-
* @return string
204-
*/
205-
protected function getS3Disk(): string
206-
{
207-
return strval(config('datatables-export.s3_disk', ''));
208-
}
209-
210203
/**
211204
* @param \Yajra\DataTables\Services\DataTable $dataTable
212205
* @return \Illuminate\Support\Collection<array-key, Column>
@@ -279,15 +272,23 @@ protected function isNumeric($value): bool
279272
}
280273

281274
/**
282-
* @param array $data
275+
* @return string
276+
*/
277+
protected function getS3Disk(): string
278+
{
279+
return strval(config('datatables-export.s3_disk', ''));
280+
}
281+
282+
/**
283+
* @param array $data
283284
* @return void
284285
*/
285286
public function sendResults(array $data): void
286287
{
287288
Mail::send('datatables-export::export-email', $data, function ($message) use ($data) {
288289
$message->attach($data['path']);
289290
$message->to($data['email'])
290-
->subject('Export Report');
291+
->subject('Export Report');
291292
$message->from(config('datatables-export.mail_from'));
292293
});
293294
}

0 commit comments

Comments
 (0)