/** */ public function testConstruct() { $object = new XMLWriter(); $object->startElement('element'); $object->text('AAA'); $object->endElement(); $this->assertEquals('<element>AAA</element>' . chr(10), $object->getData()); $object = new XMLWriter(XMLWriter::STORAGE_DISK); $object->startElement('element'); $object->text('BBB'); $object->endElement(); $this->assertEquals('<element>BBB</element>' . chr(10), $object->getData()); }
/** * @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(); }
/** * Write Override content type * * @param \PhpOffice\PhpPowerpoint\Shared\XMLWriter $objWriter XML Writer * @param string $pPartname Part name * @param string $pContentType Content type * @throws \Exception */ private function writeOverrideContentType(XMLWriter $objWriter, $pPartname = '', $pContentType = '') { if ($pPartname != '' && $pContentType != '') { // Write content type $objWriter->startElement('Override'); $objWriter->writeAttribute('PartName', $pPartname); $objWriter->writeAttribute('ContentType', $pContentType); $objWriter->endElement(); } else { throw new \Exception("Invalid parameters passed."); } }
/** * Write Type Scatter * * @param \PhpOffice\PhpPowerpoint\Shared\XMLWriter $objWriter XML Writer * @param \PhpOffice\PhpPowerpoint\Shape\Chart\Type\Scatter $subject * @param boolean $includeSheet * @throws \Exception */ protected function writeTypeScatter(XMLWriter $objWriter, Scatter $subject, $includeSheet = false) { // c:scatterChart $objWriter->startElement('c:scatterChart'); // c:scatterStyle $objWriter->startElement('c:scatterStyle'); $objWriter->writeAttribute('val', 'lineMarker'); $objWriter->endElement(); // c:varyColors $objWriter->startElement('c:varyColors'); $objWriter->writeAttribute('val', '0'); $objWriter->endElement(); // Write series $seriesIndex = 0; foreach ($subject->getData() as $series) { // c:ser $objWriter->startElement('c:ser'); // c:idx $objWriter->startElement('c:idx'); $objWriter->writeAttribute('val', $seriesIndex); $objWriter->endElement(); // c:order $objWriter->startElement('c:order'); $objWriter->writeAttribute('val', $seriesIndex); $objWriter->endElement(); // c:tx $objWriter->startElement('c:tx'); $coords = $includeSheet ? 'Sheet1!$' . \PHPExcel_Cell::stringFromColumnIndex(1 + $seriesIndex) . '$1' : ''; $this->writeSingleValueOrReference($objWriter, $includeSheet, $series->getTitle(), $coords); $objWriter->endElement(); // c:marker $objWriter->startElement('c:marker'); // c:marker $objWriter->startElement('c:symbol'); $objWriter->writeAttribute('val', 'none'); // Marker style //$objWriter->writeAttribute('size', '7'); // Marker size $objWriter->endElement(); $objWriter->endElement(); // c:dLbls $objWriter->startElement('c:dLbls'); // c:txPr $objWriter->startElement('c:txPr'); // a:bodyPr $objWriter->writeElement('a:bodyPr', null); // a:lstStyle $objWriter->writeElement('a:lstStyle', null); // a:p $objWriter->startElement('a:p'); // a:pPr $objWriter->startElement('a:pPr'); // a:defRPr $objWriter->startElement('a:defRPr'); $objWriter->writeAttribute('b', $series->getFont()->isBold() ? 'true' : 'false'); $objWriter->writeAttribute('i', $series->getFont()->isItalic() ? 'true' : 'false'); $objWriter->writeAttribute('strike', $series->getFont()->isStrikethrough() ? 'sngStrike' : 'noStrike'); $objWriter->writeAttribute('sz', $series->getFont()->getSize() * 100); $objWriter->writeAttribute('u', $series->getFont()->getUnderline()); if ($series->getFont()->isSuperScript() || $series->getFont()->isSubScript()) { if ($series->getFont()->isSuperScript()) { $objWriter->writeAttribute('baseline', '30000'); } elseif ($series->getFont()->isSubScript()) { $objWriter->writeAttribute('baseline', '-25000'); } } // Font - a:solidFill $objWriter->startElement('a:solidFill'); // a:srgbClr $objWriter->startElement('a:srgbClr'); $objWriter->writeAttribute('val', $series->getFont()->getColor()->getRGB()); $objWriter->endElement(); $objWriter->endElement(); // Font - a:latin $objWriter->startElement('a:latin'); $objWriter->writeAttribute('typeface', $series->getFont()->getName()); $objWriter->endElement(); $objWriter->endElement(); $objWriter->endElement(); // a:endParaRPr $objWriter->startElement('a:endParaRPr'); $objWriter->writeAttribute('lang', 'en-US'); $objWriter->writeAttribute('dirty', '0'); $objWriter->endElement(); $objWriter->endElement(); $objWriter->endElement(); // c:showLegendKey $this->writeElementWithValAttribute($objWriter, 'c:showLegendKey', '0'); // c:showVal $this->writeElementWithValAttribute($objWriter, 'c:showVal', $series->hasShowValue() ? '1' : '0'); // c:showCatName $this->writeElementWithValAttribute($objWriter, 'c:showCatName', $series->hasShowCategoryName() ? '1' : '0'); // c:showSerName $this->writeElementWithValAttribute($objWriter, 'c:showSerName', $series->hasShowSeriesName() ? '1' : '0'); // c:showPercent $this->writeElementWithValAttribute($objWriter, 'c:showPercent', $series->hasShowPercentage() ? '1' : '0'); // c:showLeaderLines $this->writeElementWithValAttribute($objWriter, 'c:showLeaderLines', $series->hasShowLeaderLines() ? '1' : '0'); $objWriter->endElement(); /* // c:spPr $objWriter->startElement('c:spPr'); // Write fill $this->writeFill($objWriter, $series->getFill()); $objWriter->endElement(); */ // Write X axis data $axisXData = array_keys($series->getValues()); // c:xVal $objWriter->startElement('c:xVal'); $this->writeMultipleValuesOrReference($objWriter, $includeSheet, $axisXData, 'Sheet1!$A$2:$A$' . (1 + count($axisXData))); $objWriter->endElement(); // Write Y axis data $axisYData = array_values($series->getValues()); // c:yVal $objWriter->startElement('c:yVal'); $coords = $includeSheet ? 'Sheet1!$' . \PHPExcel_Cell::stringFromColumnIndex($seriesIndex + 1) . '$2:$' . \PHPExcel_Cell::stringFromColumnIndex($seriesIndex + 1) . '$' . (1 + count($axisYData)) : ''; $this->writeMultipleValuesOrReference($objWriter, $includeSheet, $axisYData, $coords); $objWriter->endElement(); // c:smooth $objWriter->startElement('c:smooth'); $objWriter->writeAttribute('val', '0'); $objWriter->endElement(); $objWriter->endElement(); ++$seriesIndex; } // c:axId $objWriter->startElement('c:axId'); $objWriter->writeAttribute('val', '52743552'); $objWriter->endElement(); // c:axId $objWriter->startElement('c:axId'); $objWriter->writeAttribute('val', '52749440'); $objWriter->endElement(); $objWriter->endElement(); }
/** * Write hyperlink * * @param \PhpOffice\PhpPowerpoint\Shared\XMLWriter $objWriter XML Writer * @param \PhpOffice\PhpPowerpoint\AbstractShape|\PhpOffice\PhpPowerpoint\Shape\RichText\TextElement $shape */ private function writeHyperlink(XMLWriter $objWriter, $shape) { // a:hlinkClick $objWriter->startElement('a:hlinkClick'); $objWriter->writeAttribute('r:id', $shape->getHyperlink()->relationId); $objWriter->writeAttribute('tooltip', $shape->getHyperlink()->getTooltip()); if ($shape->getHyperlink()->isInternal()) { $objWriter->writeAttribute('action', $shape->getHyperlink()->getUrl()); } $objWriter->endElement(); }
/** * Write slide * * @param \PhpOffice\PhpPowerpoint\Shared\XMLWriter $objWriter XML Writer * @param int $pSlideId Slide id * @param int $pRelId Relationship ID * @throws \Exception */ private function writeSlide(XMLWriter $objWriter, $pSlideId = 1, $pRelId = 1) { // p:sldId $objWriter->startElement('p:sldId'); $objWriter->writeAttribute('id', $pSlideId); $objWriter->writeAttribute('r:id', 'rId' . $pRelId); $objWriter->endElement(); }
/** * Write relationship * * @param \PhpOffice\PhpPowerpoint\Shared\XMLWriter $objWriter XML Writer * @param int $pId Relationship ID. rId will be prepended! * @param string $pType Relationship type * @param string $pTarget Relationship target * @param string $pTargetMode Relationship target mode * @throws \Exception */ private function writeRelationship(XMLWriter $objWriter, $pId = 1, $pType = '', $pTarget = '', $pTargetMode = '') { if ($pType != '' && $pTarget != '') { if (strpos($pId, 'rId') === false) { $pId = 'rId' . $pId; } // Write relationship $objWriter->startElement('Relationship'); $objWriter->writeAttribute('Id', $pId); $objWriter->writeAttribute('Type', $pType); $objWriter->writeAttribute('Target', $pTarget); if ($pTargetMode != '') { $objWriter->writeAttribute('TargetMode', $pTargetMode); } $objWriter->endElement(); } else { throw new \Exception("Invalid parameters passed."); } }
/** * Serialize PHPPowerPoint object to XML * * @param PHPPowerPoint $pPHPPowerPoint * @param string $pFilename * @return string XML Output * @throws \Exception */ private function writeSerialized(PhpPowerpoint $pPHPPowerPoint = null, $pFilename = '') { // Clone $pPHPPowerPoint $pPHPPowerPoint = clone $pPHPPowerPoint; // Update media links $slideCount = $pPHPPowerPoint->getSlideCount(); for ($i = 0; $i < $slideCount; ++$i) { for ($j = 0; $j < $pPHPPowerPoint->getSlide($i)->getShapeCollection()->count(); ++$j) { if ($pPHPPowerPoint->getSlide($i)->getShapeCollection()->offsetGet($j) instanceof AbstractDrawing) { $pPHPPowerPoint->getSlide($i)->getShapeCollection()->offsetGet($j)->setPath('zip://' . $pFilename . '#media/' . $pPHPPowerPoint->getSlide($i)->getShapeCollection()->offsetGet($j)->getFilename(), false); } } } // Create XML writer $objWriter = new XMLWriter(); $objWriter->openMemory(); $objWriter->setIndent(true); // XML header $objWriter->startDocument('1.0', 'UTF-8', 'yes'); // PHPPowerPoint $objWriter->startElement('PHPPowerPoint'); $objWriter->writeAttribute('version', '##VERSION##'); // Comment $objWriter->writeComment('This file has been generated using PHPPowerPoint v##VERSION## (http://github.com/PHPOffice/PHPPowerPoint). It contains a base64 encoded serialized version of the PHPPowerPoint internal object.'); // Data $objWriter->startElement('data'); $objWriter->writeCData(base64_encode(serialize($pPHPPowerPoint))); $objWriter->endElement(); $objWriter->endElement(); // Return return $objWriter->getData(); }
/** * Write table Chart * @param XMLWriter $objWriter * @param Chart $shape * @param integer $shapeId */ public function writeShapeChart(XMLWriter $objWriter, Chart $shape, $shapeId) { $parentWriter = $this->getParentWriter(); if (!$parentWriter instanceof ODPresentation) { throw new \Exception('The $parentWriter is not an instance of \\PhpOffice\\PhpPowerpoint\\Writer\\ODPresentation'); } $parentWriter->chartArray[$shapeId] = $shape; // draw:frame $objWriter->startElement('draw:frame'); $objWriter->writeAttribute('draw:name', $shape->getTitle()->getText()); $objWriter->writeAttribute('svg:x', StringHelper::numberFormat(SharedDrawing::pixelsToCentimeters($shape->getOffsetX()), 3) . 'cm'); $objWriter->writeAttribute('svg:y', StringHelper::numberFormat(SharedDrawing::pixelsToCentimeters($shape->getOffsetY()), 3) . 'cm'); $objWriter->writeAttribute('svg:height', StringHelper::numberFormat(SharedDrawing::pixelsToCentimeters($shape->getHeight()), 3) . 'cm'); $objWriter->writeAttribute('svg:width', StringHelper::numberFormat(SharedDrawing::pixelsToCentimeters($shape->getWidth()), 3) . 'cm'); // draw:object $objWriter->startElement('draw:object'); $objWriter->writeAttribute('xlink:href', './Object ' . $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 * @param integer $shapeId */ public function writeShapeChart(XMLWriter $objWriter, Chart $shape, $shapeId) { $this->getParentWriter()->chartArray[$shapeId] = $shape; // draw:frame $objWriter->startElement('draw:frame'); $objWriter->writeAttribute('draw:name', $shape->getTitle()->getText()); $objWriter->writeAttribute('svg:x', String::numberFormat(SharedDrawing::pixelsToCentimeters($shape->getOffsetX()), 3) . 'cm'); $objWriter->writeAttribute('svg:y', String::numberFormat(SharedDrawing::pixelsToCentimeters($shape->getOffsetY()), 3) . 'cm'); $objWriter->writeAttribute('svg:height', String::numberFormat(SharedDrawing::pixelsToCentimeters($shape->getHeight()), 3) . 'cm'); $objWriter->writeAttribute('svg:width', String::numberFormat(SharedDrawing::pixelsToCentimeters($shape->getWidth()), 3) . 'cm'); // draw:object $objWriter->startElement('draw:object'); $objWriter->writeAttribute('xlink:href', './Object ' . $shapeId); $objWriter->writeAttribute('xlink:type', 'simple'); $objWriter->writeAttribute('xlink:show', 'embed'); // > draw:object $objWriter->endElement(); // > draw:frame $objWriter->endElement(); }