66use yii \console \Controller ;
77use yii \helpers \Console ;
88use yii \helpers \VarDumper ;
9- use \PHPExcel ;
10- use \PHPExcel_Worksheet ;
11- use \PHPExcel_IOFactory ;
12- use \PHPExcel_Cell_DataType ;
9+ use \PhpOffice \ PhpSpreadsheet \ Spreadsheet ;
10+ use \PhpOffice \ PhpSpreadsheet \ Worksheet \ Worksheet ;
11+ use \PhpOffice \ PhpSpreadsheet \ IOFactory ;
12+ use \PhpOffice \ PhpSpreadsheet \ Cell \ DataType ;
1313
1414/**
1515 * Export new translations to Excel files from PHP message files and update PHP
@@ -151,7 +151,7 @@ public function actionImport($configFile, $excelDir, $extension = 'xlsx')
151151 $ this ->stdout ("Skipping language $ language. \n" , Console::FG_YELLOW );
152152 continue ;
153153 }
154- $ excel = PHPExcel_IOFactory ::load ($ file );
154+ $ excel = \ PhpOffice \ PhpSpreadsheet \IOFactory ::load ($ file );
155155 foreach ($ excel ->getSheetNames () as $ category ) {
156156 if (!$ this ->categoryIncluded ($ category )) {
157157 $ this ->stdout ("Skipping category $ category. \n" , Console::FG_YELLOW );
@@ -225,15 +225,15 @@ protected function writeToExcelFiles($messages, $excelDir)
225225 foreach ($ messages as $ language => $ categories ) {
226226 $ file = rtrim ($ excelDir , DIRECTORY_SEPARATOR ).DIRECTORY_SEPARATOR .$ language .'.xlsx ' ;
227227 $ this ->stdout ("Writing Excel file for $ language to $ file ... " , Console::FG_GREEN );
228- $ excel = new PHPExcel ();
228+ $ excel = new \ PhpOffice \ PhpSpreadsheet \ Spreadsheet ();
229229 $ index = 0 ;
230230 foreach ($ categories as $ category => $ sources ) {
231- $ sheet = new PHPExcel_Worksheet ($ excel , $ category );
231+ $ sheet = new \ PhpOffice \ PhpSpreadsheet \ Worksheet \ Worksheet ($ excel , $ category );
232232 $ excel ->addSheet ($ sheet , $ index ++);
233233 $ sheet ->getColumnDimension ('A ' )->setWidth (60 );
234234 $ sheet ->getColumnDimension ('B ' )->setWidth (60 );
235- $ sheet ->setCellValue ('A1 ' , 'Source ' , PHPExcel_Cell_DataType ::TYPE_STRING );
236- $ sheet ->setCellValue ('B1 ' , 'Translation ' , PHPExcel_Cell_DataType ::TYPE_STRING );
235+ $ sheet ->setCellValue ('A1 ' , 'Source ' , \ PhpOffice \ PhpSpreadsheet \ Cell \DataType ::TYPE_STRING );
236+ $ sheet ->setCellValue ('B1 ' , 'Translation ' , \ PhpOffice \ PhpSpreadsheet \ Cell \DataType ::TYPE_STRING );
237237 $ sheet ->getStyle ('A1:B1 ' )->applyFromArray ([
238238 'font ' => [
239239 'bold ' => true ,
@@ -248,14 +248,14 @@ protected function writeToExcelFiles($messages, $excelDir)
248248 $ sheet ->getStyle ('B ' .$ row )->getAlignment ()->setWrapText (true );
249249 }
250250 // This does not work with LibreOffice Calc, see:
251- // https://github.com/PHPOffice/PHPExcel /issues/588
251+ // https://github.com/PHPOffice/\PhpOffice\PhpSpreadsheet\Spreadsheet /issues/588
252252 $ sheet ->getRowDimension ($ row )->setRowHeight ($ this ->lineHeight ===null ? -1 : $ this ->lineHeight );
253253 $ row ++;
254254 }
255255 }
256256 $ excel ->removeSheetByIndex ($ index );
257257 $ excel ->setActiveSheetIndex (0 );
258- $ writer = PHPExcel_IOFactory ::createWriter ($ excel , "Excel2007 " );
258+ $ writer = \ PhpOffice \ PhpSpreadsheet \IOFactory ::createWriter ($ excel , "Xlsx " );
259259 $ writer ->save ($ file );
260260 $ this ->stdout ("Done. \n" , Console::FG_GREEN );
261261 }
0 commit comments