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
@@ -40,9 +38,9 @@ class DataTableExportJob implements ShouldQueue, ShouldBeUnique
40
38
/**
41
39
* Create a new job instance.
42
40
*
43
- * @param array $dataTable
44
- * @param array $request
45
- * @param null $user
41
+ * @param array $dataTable
42
+ * @param array $request
43
+ * @param null $user
46
44
*/
47
45
public function __construct (array $ dataTable , array $ request , $ user = null )
48
46
{
@@ -78,7 +76,7 @@ public function handle()
78
76
79
77
$ type = Str::startsWith (request ('exportType ' ), Type::CSV ) ? Type::CSV : Type::XLSX ;
80
78
$ disk = config ('datatables-export.disk ' , 'local ' );
81
- $ filename = $ this ->batchId . '. ' . $ type ;
79
+ $ filename = $ this ->batchId . '. ' . $ type ;
82
80
83
81
$ path = Storage::disk ($ disk )->path ($ filename );
84
82
@@ -88,7 +86,7 @@ public function handle()
88
86
$ columns = $ oTable ->html ()->getColumns ()->filter ->exportable ;
89
87
$ writer ->addRow (
90
88
WriterEntityFactory::createRowFromArray (
91
- $ columns ->map (fn ($ column ) => strip_tags ($ column ['title ' ]))->toArray ()
89
+ $ columns ->map (fn ($ column ) => strip_tags ($ column ['title ' ]))->toArray ()
92
90
)
93
91
);
94
92
@@ -112,12 +110,16 @@ public function handle()
112
110
$ cells ->push (
113
111
WriterEntityFactory::createCell ($ date , (new StyleBuilder )->setFormat ($ format )->build ())
114
112
);
113
+ } else if ($ this ->wantsText ($ column )) {
114
+ $ cells ->push (
115
+ WriterEntityFactory::createCell ($ value , (new StyleBuilder )->setFormat ($ column ['exportFormat ' ])->build ())
116
+ );
115
117
} else {
116
118
$ format = $ column ['exportFormat ' ]
117
119
? (new StyleBuilder )->setFormat ($ column ['exportFormat ' ])->build ()
118
120
: null ;
119
121
120
- $ value = $ this ->isNumeric ($ value ) ? (float ) $ value : $ value ;
122
+ $ value = $ this ->isNumeric ($ value ) ? (float )$ value : $ value ;
121
123
122
124
$ cells ->push (WriterEntityFactory::createCell ($ value , $ format ));
123
125
}
@@ -129,7 +131,7 @@ public function handle()
129
131
}
130
132
131
133
/**
132
- * @param \Yajra\DataTables\Html\Column $column
134
+ * @param \Yajra\DataTables\Html\Column $column
133
135
* @return bool
134
136
*/
135
137
protected function wantsDateFormat (Column $ column ): bool
@@ -142,7 +144,7 @@ protected function wantsDateFormat(Column $column): bool
142
144
}
143
145
144
146
/**
145
- * @param mixed $value
147
+ * @param mixed $value
146
148
* @return bool
147
149
*/
148
150
protected function isNumeric ($ value ): bool
@@ -154,4 +156,17 @@ protected function isNumeric($value): bool
154
156
155
157
return is_numeric ($ value );
156
158
}
159
+
160
+ /**
161
+ * @param \Yajra\DataTables\Html\Column $column
162
+ * @return bool
163
+ */
164
+ protected function wantsText (Column $ column ): bool
165
+ {
166
+ if (! isset ($ column ['exportFormat ' ])) {
167
+ return false ;
168
+ }
169
+
170
+ return in_array ($ column ['exportFormat ' ], config ('datatables-export.text_formats ' , []));
171
+ }
157
172
}
0 commit comments