Get Title
public getTitle ( ) : PhpOffice\PhpPresentation\Shape\Chart\Title | ||
Résultat | PhpOffice\PhpPresentation\Shape\Chart\Title |
public function testConstruct() { $object = new Chart(); $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart\\Title', $object->getTitle()); $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart\\Legend', $object->getLegend()); $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart\\PlotArea', $object->getPlotArea()); $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart\\View3D', $object->getView3D()); }
/** * Write chart to XML format * * @param PhpPresentation $presentation * @param \PhpOffice\PhpPresentation\Shape\Chart $chart * @param string $tempName * @return string String output * @throws \Exception */ public function writeSpreadsheet(PhpPresentation $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()); $numAxisXData = count($axisXData); for ($i = 0; $i < $numAxisXData; $i++) { $sheet->setCellValueByColumnAndRow(0, $i + 2, $axisXData[$i]); } // Y-axis $axisYData = array_values($series->getValues()); $numAxisYData = count($axisYData); for ($i = 0; $i < $numAxisYData; $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); if (@unlink($tempName) === false) { throw new \Exception('The file ' . $tempName . ' could not removed.'); } return $returnValue; }
/** * Write table Chart * @param XMLWriter $objWriter * @param Chart $shape */ public function writeShapeChart(XMLWriter $objWriter, Chart $shape) { $parentWriter = $this->getParentWriter(); if (!$parentWriter instanceof ODPresentation) { throw new \Exception('The $parentWriter is not an instance of \\PhpOffice\\PhpPresentation\\Writer\\ODPresentation'); } $parentWriter->chartArray[$this->shapeId] = $shape; // draw:frame $objWriter->startElement('draw:frame'); $objWriter->writeAttribute('draw:name', $shape->getTitle()->getText()); $objWriter->writeAttribute('svg:x', Text::numberFormat(CommonDrawing::pixelsToCentimeters($shape->getOffsetX()), 3) . 'cm'); $objWriter->writeAttribute('svg:y', Text::numberFormat(CommonDrawing::pixelsToCentimeters($shape->getOffsetY()), 3) . 'cm'); $objWriter->writeAttribute('svg:height', Text::numberFormat(CommonDrawing::pixelsToCentimeters($shape->getHeight()), 3) . 'cm'); $objWriter->writeAttribute('svg:width', Text::numberFormat(CommonDrawing::pixelsToCentimeters($shape->getWidth()), 3) . 'cm'); // draw:object $objWriter->startElement('draw:object'); $objWriter->writeAttribute('xlink:href', './Object ' . $this->shapeId); $objWriter->writeAttribute('xlink:type', 'simple'); $objWriter->writeAttribute('xlink:show', 'embed'); // > draw:object $objWriter->endElement(); // > draw:frame $objWriter->endElement(); }
/** * Write table Chart * @param XMLWriter $objWriter * @param Chart $shape * @throws \Exception */ public function writeShapeChart(XMLWriter $objWriter, Chart $shape) { $arrayChart = $this->getArrayChart(); $arrayChart[$this->shapeId] = $shape; $this->setArrayChart($arrayChart); // draw:frame $objWriter->startElement('draw:frame'); $objWriter->writeAttribute('draw:name', $shape->getTitle()->getText()); $objWriter->writeAttribute('svg:x', Text::numberFormat(CommonDrawing::pixelsToCentimeters($shape->getOffsetX()), 3) . 'cm'); $objWriter->writeAttribute('svg:y', Text::numberFormat(CommonDrawing::pixelsToCentimeters($shape->getOffsetY()), 3) . 'cm'); $objWriter->writeAttribute('svg:height', Text::numberFormat(CommonDrawing::pixelsToCentimeters($shape->getHeight()), 3) . 'cm'); $objWriter->writeAttribute('svg:width', Text::numberFormat(CommonDrawing::pixelsToCentimeters($shape->getWidth()), 3) . 'cm'); // draw:object $objWriter->startElement('draw:object'); $objWriter->writeAttribute('xlink:href', './Object ' . $this->shapeId); $objWriter->writeAttribute('xlink:type', 'simple'); $objWriter->writeAttribute('xlink:show', 'embed'); // > draw:object $objWriter->endElement(); // > draw:frame $objWriter->endElement(); }