33namespace Yajra \DataTables \Jobs ;
44
55use Carbon \Carbon ;
6+ use DateTimeInterface ;
67use Illuminate \Auth \Events \Login ;
78use Illuminate \Bus \Batchable ;
89use Illuminate \Bus \Queueable ;
2021use Illuminate \Support \Facades \Mail ;
2122use Illuminate \Support \Facades \Storage ;
2223use 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 ;
2729use OpenSpout \Writer \XLSX \Writer as XLSXWriter ;
28- use PhpOffice \PhpSpreadsheet \Shared \Date ;
2930use PhpOffice \PhpSpreadsheet \Style \NumberFormat ;
3031use Yajra \DataTables \Html \Column ;
3132use 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