Skip to content

Commit a3c9a6c

Browse files
author
matijadg
authored
Merge pull request #1 from degordian/phpspreadsheet
Replace PHPExcel with Phpspreadsheet
2 parents 5fed83c + aec3c59 commit a3c9a6c

File tree

3 files changed

+20
-22
lines changed

3 files changed

+20
-22
lines changed

ExcelMessageController.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
use yii\console\Controller;
77
use yii\helpers\Console;
88
use 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
}

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ With this extension you can export messages from PHP message files to Excel,
1616
send them to your translators and read them back into your message files.
1717

1818
> **Note:** To read and write to and from Excel file, we use the excellent
19-
> [PHPExcel](https://github.com/PHPOffice/PHPExcel) package.
19+
> [PhpSpreadsheet](https://github.com/PHPOffice/PhpSpreadsheet) package.
2020
2121

2222
## Installation
@@ -75,7 +75,7 @@ This will add the new translations to your PHP message files. Yes it's
7575
really that simple.
7676

7777
You can also pass a third parameter with the file extension, the default is `xlsx`
78-
as used by Excel2007 files. PHPExcel should also autodetect other Excel formats
78+
as used by Excel 2007+ files. \PhpOffice\PhpSpreadsheet\Spreadsheet should also autodetect other Excel formats
7979

8080
> **Note:** The files must be provided in the same format as they where created by
8181
> the export:

composer.json

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,17 @@
44
"keywords": ["yii2", "i18n", "excel"],
55
"type": "yii2-extension",
66
"license": "MIT",
7-
"authors": [
8-
{
9-
"name": "Michael Härtl",
10-
"email": "[email protected]"
11-
}
12-
],
7+
"authors": [{
8+
"name": "Michael Härtl",
9+
"email": "[email protected]"
10+
}],
1311
"require": {
14-
"yiisoft/yii2": "*",
15-
"phpoffice/phpexcel": "1.*"
12+
"yiisoft/yii2": "*",
13+
"phpoffice/phpspreadsheet": "^1.2"
1614
},
1715
"autoload": {
1816
"psr-4": {
1917
"codemix\\excelmessage\\": ""
2018
}
2119
}
22-
}
20+
}

0 commit comments

Comments
 (0)