Skip to content

Commit

Permalink
#634 : Migrated use of PHPExcel to PhpSpreadsheet
Browse files Browse the repository at this point in the history
  • Loading branch information
Progi1984 committed Jul 6, 2021
1 parent 0b7b2f5 commit bd25be6
Show file tree
Hide file tree
Showing 8 changed files with 194 additions and 171 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
"php": "^7.1|^8.0",
"ext-xml": "*",
"ext-zip": "*",
"phpoffice/common": "0.2.*"
"phpoffice/common": "0.2.*",
"phpoffice/phpspreadsheet": "^1.9.0"
},
"require-dev": {
"phpunit/phpunit": ">=7.0",
Expand Down
1 change: 1 addition & 0 deletions docs/changes/1.0.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
- PHP 7.1 is now supported - @Progi1984 GH-355
- Added support PHP 7.4 to 8.0 & Removed support PHP < 7.1 - @Progi1984 GH-636
- Removed deprecated methods/classes - @Progi1984 GH-650
- Migrated use of PHPExcel to PhpSpreadsheet - @Progi1984 GH-652
- PhpOffice\PhpPresentation\Style\Color : Define only the transparency - @Progi1984 GH-370
- PowerPoint2007 Reader : Background Color based on SchemeColor - @Progi1984 GH-397
- PowerPoint2007 Reader : Support for hyperlinks under pictures - @ulziibuyan
Expand Down
3 changes: 0 additions & 3 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ parameters:
- tests
reportUnmatchedIgnoredErrors: false
ignoreErrors:
## Relative to PHPExcel
- '#^Call to static method createWriter\(\) on an unknown class PHPExcel_IOFactory\.#'
- '#^Call to static method stringFromColumnIndex\(\) on an unknown class PHPExcel_Cell\.#'
## Relative to Common
- '#^Parameter \#1 \$pValue of static method PhpOffice\\Common\\Drawing\:\:angleToDegrees\(\) expects int, string given\.#'
- '#^Parameter \#1 \$pValue of static method PhpOffice\\Common\\Drawing\:\:centimetersToPixels\(\) expects int, string given\.#'
Expand Down
122 changes: 0 additions & 122 deletions samples/Sample_05_Chart_with_PHPExcel.php

This file was deleted.

119 changes: 119 additions & 0 deletions samples/Sample_05_Chart_with_PhpSpreadsheet.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
<?php

include_once 'Sample_Header.php';

use PhpOffice\PhpPresentation\PhpPresentation;
use PhpOffice\PhpPresentation\Shape\Chart\Series;
use PhpOffice\PhpPresentation\Shape\Chart\Type\Bar3D;
use PhpOffice\PhpPresentation\Shape\Chart\Type\Pie3D;
use PhpOffice\PhpPresentation\Style\Border;
use PhpOffice\PhpPresentation\Style\Color;
use PhpOffice\PhpPresentation\Style\Fill;

// Create new PHPPresentation object
echo date('H:i:s') . ' Create new PHPPresentation object' . EOL;
$objPHPPresentation = new PhpPresentation();

// Set properties
echo date('H:i:s') . ' Set properties' . EOL;
$objPHPPresentation->getDocumentProperties()->setCreator('PHPOffice')
->setLastModifiedBy('PHPPresentation Team')
->setTitle('Sample 08 Title')
->setSubject('Sample 08 Subject')
->setDescription('Sample 08 Description')
->setKeywords('office 2007 openxml libreoffice odt php')
->setCategory('Sample Category');

// Remove first slide
echo date('H:i:s') . ' Remove first slide' . EOL;
$objPHPPresentation->removeSlideByIndex(0);

// Create templated slide
echo date('H:i:s') . ' Create templated slide' . EOL;
$currentSlide = createTemplatedSlide($objPHPPresentation); // local function

// Generate sample data for first chart
echo date('H:i:s') . ' Generate sample data for first chart' . EOL;
$series1Data = ['Jan' => 133, 'Feb' => 99, 'Mar' => 191, 'Apr' => 205, 'May' => 167, 'Jun' => 201, 'Jul' => 240, 'Aug' => 226, 'Sep' => 255, 'Oct' => 264, 'Nov' => 283, 'Dec' => 293];
$series2Data = ['Jan' => 266, 'Feb' => 198, 'Mar' => 271, 'Apr' => 305, 'May' => 267, 'Jun' => 301, 'Jul' => 340, 'Aug' => 326, 'Sep' => 344, 'Oct' => 364, 'Nov' => 383, 'Dec' => 379];

// Create a bar chart (that should be inserted in a shape)
echo date('H:i:s') . ' Create a bar chart (that should be inserted in a chart shape)' . EOL;
$bar3DChart = new Bar3D();
$bar3DChart->addSeries(new Series('2009', $series1Data));
$bar3DChart->addSeries(new Series('2010', $series2Data));

// Create a shape (chart)
echo date('H:i:s') . ' Create a shape (chart)' . EOL;
$shape = $currentSlide->createChartShape();
$shape->setName('PHPPresentation Monthly Downloads')
->setResizeProportional(false)
->setHeight(550)
->setWidth(700)
->setOffsetX(120)
->setOffsetY(80)
->setIncludeSpreadsheet(true);
$shape->getShadow()->setVisible(true)
->setDirection(45)
->setDistance(10);
$shape->getFill()->setFillType(Fill::FILL_GRADIENT_LINEAR)
->setStartColor(new Color('FFCCCCCC'))
->setEndColor(new Color('FFFFFFFF'))
->setRotation(270);
$shape->getBorder()->setLineStyle(Border::LINE_SINGLE);
$shape->getTitle()->setText('PHPPresentation Monthly Downloads');
$shape->getTitle()->getFont()->setItalic(true);
$shape->getPlotArea()->getAxisX()->setTitle('Month');
$shape->getPlotArea()->getAxisY()->setTitle('Downloads');
$shape->getPlotArea()->setType($bar3DChart);
$shape->getView3D()->setRightAngleAxes(true);
$shape->getView3D()->setRotationX(20);
$shape->getView3D()->setRotationY(20);
$shape->getLegend()->getBorder()->setLineStyle(Border::LINE_SINGLE);
$shape->getLegend()->getFont()->setItalic(true);

// Create templated slide
echo date('H:i:s') . ' Create templated slide' . EOL;
$currentSlide = createTemplatedSlide($objPHPPresentation); // local function

// Generate sample data for second chart
echo date('H:i:s') . ' Generate sample data for second chart' . EOL;
$seriesData = ['Monday' => 12, 'Tuesday' => 15, 'Wednesday' => 13, 'Thursday' => 17, 'Friday' => 14, 'Saturday' => 9, 'Sunday' => 7];

// Create a pie chart (that should be inserted in a shape)
echo date('H:i:s') . ' Create a pie chart (that should be inserted in a chart shape)' . EOL;
$pie3DChart = new Pie3D();
$pie3DChart->addSeries(new Series('Downloads', $seriesData));

// Create a shape (chart)
echo date('H:i:s') . ' Create a shape (chart)' . EOL;
$shape = $currentSlide->createChartShape();
$shape->setName('PHPPresentation Daily Downloads')
->setResizeProportional(false)
->setHeight(550)
->setWidth(700)
->setOffsetX(120)
->setOffsetY(80)
->setIncludeSpreadsheet(true);
$shape->getShadow()->setVisible(true)
->setDirection(45)
->setDistance(10);
$shape->getFill()->setFillType(Fill::FILL_GRADIENT_LINEAR)
->setStartColor(new Color('FFCCCCCC'))
->setEndColor(new Color('FFFFFFFF'))
->setRotation(270);
$shape->getBorder()->setLineStyle(Border::LINE_SINGLE);
$shape->getTitle()->setText('PHPPresentation Daily Downloads');
$shape->getTitle()->getFont()->setItalic(true);
$shape->getPlotArea()->setType($pie3DChart);
$shape->getView3D()->setRotationX(30);
$shape->getView3D()->setPerspective(30);
$shape->getLegend()->getBorder()->setLineStyle(Border::LINE_SINGLE);
$shape->getLegend()->getFont()->setItalic(true);

// Save file
echo write($objPHPPresentation, basename(__FILE__, '.php'), $writers);

if (!CLI) {
include_once 'Sample_Footer.php';
}
38 changes: 19 additions & 19 deletions src/PhpPresentation/Shape/Chart.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,33 +32,33 @@ class Chart extends AbstractGraphic implements ComparableInterface
/**
* Title.
*
* @var \PhpOffice\PhpPresentation\Shape\Chart\Title
* @var Title
*/
private $title;

/**
* Legend.
*
* @var \PhpOffice\PhpPresentation\Shape\Chart\Legend
* @var Legend
*/
private $legend;

/**
* Plot area.
*
* @var \PhpOffice\PhpPresentation\Shape\Chart\PlotArea
* @var PlotArea
*/
private $plotArea;

/**
* View 3D.
*
* @var \PhpOffice\PhpPresentation\Shape\Chart\View3D
* @var View3D
*/
private $view3D;

/**
* Include spreadsheet for editing data? Requires PHPExcel in the same folder as PhpPresentation.
* Is the spreadsheet included for editing data ?
*
* @var bool
*/
Expand Down Expand Up @@ -92,61 +92,61 @@ public function __clone()
/**
* Get Title.
*
* @return \PhpOffice\PhpPresentation\Shape\Chart\Title
* @return Title
*/
public function getTitle()
public function getTitle(): Title
{
return $this->title;
}

/**
* Get Legend.
*
* @return \PhpOffice\PhpPresentation\Shape\Chart\Legend
* @return Legend
*/
public function getLegend()
public function getLegend(): Legend
{
return $this->legend;
}

/**
* Get PlotArea.
*
* @return \PhpOffice\PhpPresentation\Shape\Chart\PlotArea
* @return PlotArea
*/
public function getPlotArea()
public function getPlotArea(): PlotArea
{
return $this->plotArea;
}

/**
* Get View3D.
*
* @return \PhpOffice\PhpPresentation\Shape\Chart\View3D
* @return View3D
*/
public function getView3D()
public function getView3D(): View3D
{
return $this->view3D;
}

/**
* Include spreadsheet for editing data? Requires PHPExcel in the same folder as PhpPresentation.
* Is the spreadsheet included for editing data ?
*
* @return bool
*/
public function hasIncludedSpreadsheet()
public function hasIncludedSpreadsheet(): bool
{
return $this->includeSpreadsheet;
}

/**
* Include spreadsheet for editing data? Requires PHPExcel in the same folder as PhpPresentation.
* Is the spreadsheet included for editing data ?
*
* @param bool $value
*
* @return \PhpOffice\PhpPresentation\Shape\Chart
* @return self
*/
public function setIncludeSpreadsheet($value = false)
public function setIncludeSpreadsheet(bool $value = false): self
{
$this->includeSpreadsheet = $value;

Expand All @@ -158,7 +158,7 @@ public function setIncludeSpreadsheet($value = false)
*
* @return string
*/
public function getIndexedFilename()
public function getIndexedFilename(): string
{
return 'chart' . $this->getImageIndex() . '.xml';
}
Expand Down
Loading

0 comments on commit bd25be6

Please sign in to comment.