2121use OpenSpout \Common \Type ;
2222use OpenSpout \Writer \Common \Creator \Style \StyleBuilder ;
2323use OpenSpout \Writer \Common \Creator \WriterEntityFactory ;
24+ use OpenSpout \Writer \XLSX \Writer as XLSXWriter ;
2425use PhpOffice \PhpSpreadsheet \Shared \Date ;
2526use PhpOffice \PhpSpreadsheet \Style \NumberFormat ;
2627use Yajra \DataTables \Html \Column ;
@@ -40,6 +41,8 @@ class DataTableExportJob implements ShouldQueue, ShouldBeUnique
4041
4142 public array $ request ;
4243
44+ public string $ sheetName ;
45+
4346 /**
4447 * @var int|string
4548 */
@@ -51,13 +54,15 @@ class DataTableExportJob implements ShouldQueue, ShouldBeUnique
5154 * @param array $dataTable
5255 * @param array $request
5356 * @param int|string $user
57+ * @param string $sheetName
5458 */
55- public function __construct (array $ dataTable , array $ request , $ user )
59+ public function __construct (array $ dataTable , array $ request , $ user, string $ sheetName = ' Sheet1 ' )
5660 {
5761 $ this ->dataTable = $ dataTable [0 ];
5862 $ this ->attributes = $ dataTable [1 ];
5963 $ this ->request = $ request ;
6064 $ this ->user = $ user ;
65+ $ this ->sheetName = $ sheetName ;
6166 }
6267
6368 /**
@@ -99,6 +104,11 @@ public function handle()
99104 $ writer = WriterEntityFactory::createWriter ($ type );
100105 $ writer ->openToFile ($ path );
101106
107+ if ($ writer instanceof XLSXWriter) {
108+ $ sheet = $ writer ->getCurrentSheet ();
109+ $ sheet ->setName (substr ($ this ->sheetName ,0 ,31 ));
110+ }
111+
102112 $ columns = $ this ->getExportableColumns ($ oTable );
103113 $ writer ->addRow (
104114 WriterEntityFactory::createRowFromArray (
@@ -166,6 +176,7 @@ public function handle()
166176
167177 $ writer ->addRow (WriterEntityFactory::createRow ($ cells ));
168178 }
179+
169180 $ writer ->close ();
170181 }
171182
0 commit comments