PHP Powerpoint and Graphics

I am trying to create PowerPoint presentations via PHP using this library . When I try to create diagram objects inside PowerPoint, I cannot edit diagrams when I upload a file and open them in Microsoft Office.

Is there a library that can create charts inside a PowerPoint file and allow editing through Office PowerPoint?

An example chart created using the above library

+6
source share
4 answers

This will probably be a bug with PHP Power Point.

However, the latest version of PHPExcel supports Charting and is actively supported. It allows you to display and export data to excel, which can be easily copied to PowerPoint.

In a personal note, I suggest you use the Google Chart Tools or RaphaelJS .

Example chart

If you want to use the chart in PowerPoint, you can easily export Google Chart data to Excel (CSV). Also see this example .

If you are specifically introducing Google Analytics, you should read this document on how to create accurate, automatically updated graphs and data in PowerPoint from Google Analytics. It mainly uses the oomfo plugin for PowerPoint.

Alternatively, there are paid solutions such as ShufflePoint .

+6
source

Of course, you can export editable charts using PHPPowerPoint. There are two examples in the tests. The first example does not include Excel worksheets and why the charts cannot be modified. But if you look at the second example, I think test8, then you will see that there is a link to PHPExcel and a flag to include the data sheet along with the chart, and then you can edit the data.

+3
source

See this URL: -

PHP PowerPoint 2007 Classes

A project that provides a set of classes for the PHP programming language, which allows you to write and read from different file formats, such as PowerPoint 2007, ... This project is built on the basis of the Microsoft OpenXML and PHP standards.

http://phppowerpoint.codeplex.com/

http://phppowerpoint.codeplex.com/sourcecontrol/list/changesets?ProjectName=phppowerpoint

Functions

http://phppowerpoint.codeplex.com/wikipage?title=Features&referringTitle=Home

try the following: -

<?php /** Error reporting */ error_reporting(E_ALL); /** Include path **/ set_include_path(get_include_path() . PATH_SEPARATOR . '/Classes/'); /** PHPPowerPoint */ include 'Classes/PHPPowerPoint.php'; // Create new PHPPowerPoint object $objPHPPowerPoint = new PHPPowerPoint(); $objPHPPowerPoint->getProperties()->setCreator("Maarten Balliauw")-> setLastModifiedBy("Maarten Balliauw")->setTitle("Office 2007 PPTX Test Document")-> setSubject("Office 2007 PPTX Test Document")->setDescription("Test document for Office 2007 PPTX, generated using PHP classes.")-> setKeywords("office 2007 openxml php")->setCategory("Test result file"); // Remove first slide $objPHPPowerPoint->removeSlideByIndex(0); // Create templated slide // Create templated slide $currentSlide = createTemplatedSlide($objPHPPowerPoint); // Generate sample data for line chart $seriesData = array('Jul 17' => 15, 'Jul 18' => 27, 'Jul 19' => 17, 'Jul 20' => 11, 'Jul 21' => 7, 'Jul 22' => 2, 'Jul 23' => 8); // Create a line chart (that should be inserted in a shape) $lineChart = new PHPPowerPoint_Shape_Chart_Type_Scatter(); $series = new PHPPowerPoint_Shape_Chart_Series('Visits', $seriesData); //$series->setShowSeriesName(true); $lineChart->addSeries($series); // Create a shape (chart) $shape = $currentSlide->createChartShape(); $shape->setName('# of people visiting your website')->setResizeProportional(false)->setHeight(550)-> setWidth(700)->setOffsetX(120)->setOffsetY(80); $shape->getShadow()->setVisible(true)->setDirection(45)->setDistance(10); $shape->getFill()->setFillType(PHPPowerPoint_Style_Fill::FILL_GRADIENT_LINEAR)-> setStartColor(new PHPPowerPoint_Style_Color('FFCCCCCC'))->setEndColor(new PHPPowerPoint_Style_Color('FFFFFFFF'))->setRotation(270); $shape->getBorder()->setLineStyle(PHPPowerPoint_Style_Border::LINE_SINGLE); $shape->getTitle()->setText('# of people visiting your website'); $shape->getTitle()->getFont()->setItalic(true); $shape->getPlotArea()->setType($lineChart); $shape->getView3D()->setRotationX(30); $shape->getView3D()->setPerspective(30); $shape->getLegend()->getBorder()->setLineStyle(PHPPowerPoint_Style_Border:: LINE_SINGLE); $shape->getLegend()->getFont()->setItalic(true); // Save PowerPoint 2007 file $objWriter = PHPPowerPoint_IOFactory::createWriter($objPHPPowerPoint, 'PowerPoint2007'); $objWriter->save(str_replace('.php', '.pptx', __file__)); function createTemplatedSlide(PHPPowerPoint $objPHPPowerPoint) { // Create slide $slide = $objPHPPowerPoint->createSlide(); // Return slide return $slide; } 
+2
source

Now the correct example is called:

Sample_05_Chart_with_PHPExcel.php

in the samples folder inside the main PHPPowerpoint folder (now it starts to call it PHPPresentation)

Please note that for it to work you need to change / add a few things.

  • download from GitHub and save the Common folder somewhere from PHPOffice

  • enable and register autoloader with Common

  • Download from GitHub and save the PHPExcel folder PHPExcel

  • include main PHPExcel.php file

  • In the Sample_Header.php file Sample_Header.php I changed the line

    Autoloader::register();

    to

    PhpOffice\PhpPresentation\Autoloader::register();

    to avoid conflicts (which autoloader are we registering?)

  • In the Sample_Header.php file Sample_Header.php I also deleted (commented out) the line:

    //require_once __DIR__ . '/../vendor/autoload.php';

    which gave me errors (I do not use a composer and do not want a composer).

That's all, now he is creating a Powerpoint presentation with editable Excel data inside.

This is the final code in the modified Sample_Header.php (lines 26-28):

 PhpOffice\PhpPresentation\Autoloader::register(); //require_once __DIR__ . '/../vendor/autoload.php'; 

This is the final code added in the modified Sample_05_Chart_with_PHPExcel.php (line 5, after include_once 'Sample_Header.php'; ):

 require_once '<path to phpExcel...>/Classes/PHPExcel.php'; include '<path to Common...>/Common/Autoloader.php'; PhpOffice\Common\Autoloader::register(); 

Change <path to phpExcel...> and <path to Common...> to the correct paths.

0
source

Source: https://habr.com/ru/post/921207/


All Articles