Skip to content

Fix #613: Replace PHPExcel with PhpSpreadsheet #614

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions src/PhpPresentation/Writer/PowerPoint2007/PptCharts.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
use PhpOffice\PhpPresentation\Shape\Chart\Type\Scatter;
use PhpOffice\PhpPresentation\Style\Border;
use PhpOffice\PhpPresentation\Style\Fill;
use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\Spreadsheet;

class PptCharts extends AbstractDecoratorWriter
{
Expand All @@ -36,7 +38,7 @@ public function render()

if ($shape->hasIncludedSpreadsheet()) {
$this->getZip()->addFromString('ppt/charts/_rels/' . $shape->getIndexedFilename() . '.rels', $this->writeChartRelationships($shape));
$pFilename = tempnam(sys_get_temp_dir(), 'PHPExcel');
$pFilename = tempnam(sys_get_temp_dir(), 'PhpSpreadsheet');
$this->getZip()->addFromString('ppt/embeddings/' . $shape->getIndexedFilename() . '.xlsx', $this->writeSpreadsheet($this->getPresentation(), $shape, $pFilename . '.xlsx'));

// remove temp file
Expand Down Expand Up @@ -214,13 +216,13 @@ public function writeSpreadsheet(PhpPresentation $presentation, $chart, $tempNam
throw new \Exception('No spreadsheet output is required for the given chart.');
}

// Verify PHPExcel
if (!class_exists('PHPExcel')) {
throw new \Exception('PHPExcel has not been loaded. Include PHPExcel.php in your script, e.g. require_once \'PHPExcel.php\'.');
// Verify PhpSpreadsheet
if (!class_exists(Spreadsheet::class)) {
throw new \Exception('PhpSpreadsheet has not been loaded. Include PhpSpreadsheet in your script, e.g. composer require phpoffice/phpspreadsheet');
}

// Create new spreadsheet
$workbook = new \PHPExcel();
$workbook = new Spreadsheet();

// Set properties
$title = $chart->getTitle()->getText();
Expand Down Expand Up @@ -257,7 +259,7 @@ public function writeSpreadsheet(PhpPresentation $presentation, $chart, $tempNam
}

// Save to string
$writer = \PHPExcel_IOFactory::createWriter($workbook, 'Excel2007');
$writer = IOFactory::createWriter($workbook, 'Xlsx');
$writer->save($tempName);

// Load file in memory
Expand Down