コード例 #1
0
 public function testConstruct()
 {
     $object = new Chart();
     $this->assertInstanceOf('PhpOffice\\PhpPowerpoint\\Shape\\Chart\\Title', $object->getTitle());
     $this->assertInstanceOf('PhpOffice\\PhpPowerpoint\\Shape\\Chart\\Legend', $object->getLegend());
     $this->assertInstanceOf('PhpOffice\\PhpPowerpoint\\Shape\\Chart\\PlotArea', $object->getPlotArea());
     $this->assertInstanceOf('PhpOffice\\PhpPowerpoint\\Shape\\Chart\\View3D', $object->getView3D());
 }
コード例 #2
0
 /**
  * @param Chart $chart
  */
 private function writeWallStyle(Chart $chart)
 {
     $chartType = $chart->getPlotArea()->getType();
     // style:style
     $this->xmlContent->startElement('style:style');
     $this->xmlContent->writeAttribute('style:name', 'styleWall');
     $this->xmlContent->writeAttribute('style:family', 'chart');
     // style:chart-properties
     $this->xmlContent->startElement('style:graphic-properties');
     //@todo : Permit edit color and size border of wall
     if ($chartType instanceof Line || $chartType instanceof Scatter) {
         $this->xmlContent->writeAttribute('draw:fill', 'solid');
         $this->xmlContent->writeAttribute('draw:fill-color', '#FFFFFF');
     } else {
         $this->xmlContent->writeAttribute('draw:fill', 'none');
         $this->xmlContent->writeAttribute('draw:stroke', 'solid');
         $this->xmlContent->writeAttribute('svg:stroke-width', '0.026cm');
         $this->xmlContent->writeAttribute('svg:stroke-color', '#878787');
     }
     // > style:chart-properties
     $this->xmlContent->endElement();
     // > style:style
     $this->xmlContent->endElement();
 }
コード例 #3
0
ファイル: Chart.php プロジェクト: cleverape/phppowerpoint
 /**
  * Write chart to XML format
  *
  * @param  PHPPowerPoint             $presentation
  * @param  \PhpOffice\PhpPowerpoint\Shape\Chart $chart
  * @param  string                    $tempName
  * @return string                    String output
  * @throws \Exception
  */
 public function writeSpreadsheet(PHPPowerPoint $presentation, $chart, $tempName)
 {
     // Need output?
     if (!$chart->hasIncludedSpreadsheet()) {
         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\'.');
     }
     // Create new spreadsheet
     $workbook = new \PHPExcel();
     // Set properties
     $title = $chart->getTitle()->getText();
     if (strlen($title) == 0) {
         $title = 'Chart';
     }
     $workbook->getProperties()->setCreator($presentation->getProperties()->getCreator())->setLastModifiedBy($presentation->getProperties()->getLastModifiedBy())->setTitle($title);
     // Add chart data
     $sheet = $workbook->setActiveSheetIndex(0);
     $sheet->setTitle('Sheet1');
     // Write series
     $seriesIndex = 0;
     foreach ($chart->getPlotArea()->getType()->getData() as $series) {
         // Title
         $sheet->setCellValueByColumnAndRow(1 + $seriesIndex, 1, $series->getTitle());
         // X-axis
         $axisXData = array_keys($series->getValues());
         for ($i = 0; $i < count($axisXData); $i++) {
             $sheet->setCellValueByColumnAndRow(0, $i + 2, $axisXData[$i]);
         }
         // Y-axis
         $axisYData = array_values($series->getValues());
         for ($i = 0; $i < count($axisYData); $i++) {
             $sheet->setCellValueByColumnAndRow(1 + $seriesIndex, $i + 2, $axisYData[$i]);
         }
         ++$seriesIndex;
     }
     // Save to string
     $writer = \PHPExcel_IOFactory::createWriter($workbook, 'Excel2007');
     $writer->save($tempName);
     // Load file in memory
     $returnValue = file_get_contents($tempName);
     @unlink($tempName);
     return $returnValue;
 }