本文整理汇总了PHP中PhpOffice\PhpPresentation\PhpPresentation::getSlide方法的典型用法代码示例。如果您正苦于以下问题:PHP PhpPresentation::getSlide方法的具体用法?PHP PhpPresentation::getSlide怎么用?PHP PhpPresentation::getSlide使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PhpOffice\PhpPresentation\PhpPresentation
的用法示例。
在下文中一共展示了PhpPresentation::getSlide方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: allDrawings
/**
* Get an array of all drawings
*
* @param PhpPresentation $pPhpPresentation
* @return \PhpOffice\PhpPresentation\Shape\AbstractDrawing[] All drawings in PhpPresentation
* @throws \Exception
*/
public function allDrawings(PhpPresentation $pPhpPresentation)
{
// Get an array of all drawings
$aDrawings = array();
// Loop trough PhpPresentation
$slideCount = $pPhpPresentation->getSlideCount();
for ($i = 0; $i < $slideCount; ++$i) {
// Loop trough images and add to array
if ($pPhpPresentation->getSlide($i)->getShapeCollection()->count() > 0) {
$iterator = $pPhpPresentation->getSlide($i)->getShapeCollection()->getIterator();
while ($iterator->valid()) {
if ($iterator->current() instanceof AbstractDrawing && !$iterator->current() instanceof Table) {
$aDrawings[] = $iterator->current();
} elseif ($iterator->current() instanceof Group) {
$iterator2 = $iterator->current()->getShapeCollection()->getIterator();
while ($iterator2->valid()) {
if ($iterator2->current() instanceof AbstractDrawing && !$iterator2->current() instanceof Table) {
$aDrawings[] = $iterator2->current();
}
$iterator2->next();
}
}
$iterator->next();
}
}
}
return $aDrawings;
}
示例2: save
/**
* Save PhpPresentation to file
*
* @param string $pFilename
* @throws \Exception
*/
public function save($pFilename)
{
if (empty($pFilename)) {
throw new \Exception("Filename is empty.");
}
if (!is_null($this->presentation)) {
// Create new ZIP file and open it for writing
$objZip = new \ZipArchive();
// Try opening the ZIP file
if ($objZip->open($pFilename, \ZipArchive::CREATE) !== true) {
if ($objZip->open($pFilename, \ZipArchive::OVERWRITE) !== true) {
throw new \Exception("Could not open " . $pFilename . " for writing.");
}
}
// Add media
$slideCount = $this->presentation->getSlideCount();
for ($i = 0; $i < $slideCount; ++$i) {
for ($j = 0; $j < $this->presentation->getSlide($i)->getShapeCollection()->count(); ++$j) {
if ($this->presentation->getSlide($i)->getShapeCollection()->offsetGet($j) instanceof AbstractDrawing) {
$imgTemp = $this->presentation->getSlide($i)->getShapeCollection()->offsetGet($j);
$objZip->addFromString('media/' . $imgTemp->getFilename(), file_get_contents($imgTemp->getPath()));
}
}
}
// Add PhpPresentation.xml to the document, which represents a PHP serialized PhpPresentation object
$objZip->addFromString('PhpPresentation.xml', $this->writeSerialized($this->presentation, $pFilename));
// Close file
if ($objZip->close() === false) {
throw new \Exception("Could not close zip file {$pFilename}.");
}
} else {
throw new \Exception("PhpPresentation object unassigned.");
}
}
示例3: fnSlide_Bar3DHorizontal
function fnSlide_Bar3DHorizontal(PhpPresentation $objPHPPresentation)
{
global $oFill;
global $oShadow;
// Create a bar chart (that should be inserted in a shape)
echo date('H:i:s') . ' Create a horizontal bar chart (that should be inserted in a chart shape) ' . EOL;
$bar3DChartHorz = clone $objPHPPresentation->getSlide(5)->getShapeCollection()->offsetGet(1)->getPlotArea()->getType();
$bar3DChartHorz->setBarDirection(Bar3D::DIRECTION_HORIZONTAL);
// Create templated slide
echo EOL . date('H:i:s') . ' Create templated slide' . EOL;
$currentSlide = createTemplatedSlide($objPHPPresentation);
// 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);
$shape->setShadow($oShadow);
$shape->setFill($oFill);
$shape->getBorder()->setLineStyle(Border::LINE_SINGLE);
$shape->getTitle()->setText('PHPPresentation Monthly Downloads');
$shape->getTitle()->getFont()->setItalic(true);
$shape->getTitle()->getAlignment()->setHorizontal(Alignment::HORIZONTAL_RIGHT);
$shape->getPlotArea()->getAxisX()->setTitle('Month');
$shape->getPlotArea()->getAxisY()->setTitle('Downloads');
$shape->getPlotArea()->setType($bar3DChartHorz);
$shape->getView3D()->setRightAngleAxes(true);
$shape->getView3D()->setRotationX(20);
$shape->getView3D()->setRotationY(20);
$shape->getLegend()->getBorder()->setLineStyle(Border::LINE_SINGLE);
$shape->getLegend()->getFont()->setItalic(true);
}
示例4: writeContentTypes
/**
* Write content types to XML format
*
* @param PhpPresentation $pPhpPresentation
* @return string XML Output
* @throws \Exception
*/
public function writeContentTypes(PhpPresentation $pPhpPresentation)
{
$parentWriter = $this->getParentWriter();
if (!$parentWriter instanceof PowerPoint2007) {
throw new \Exception('The $parentWriter is not an instance of \\PhpOffice\\PhpPresentation\\Writer\\PowerPoint2007');
}
// Create XML writer
$objWriter = $this->getXMLWriter();
// XML header
$objWriter->startDocument('1.0', 'UTF-8', 'yes');
// Types
$objWriter->startElement('Types');
$objWriter->writeAttribute('xmlns', 'http://schemas.openxmlformats.org/package/2006/content-types');
// Rels
$this->writeDefaultContentType($objWriter, 'rels', 'application/vnd.openxmlformats-package.relationships+xml');
// XML
$this->writeDefaultContentType($objWriter, 'xml', 'application/xml');
// Themes
$masterSlides = $parentWriter->getLayoutPack()->getMasterSlides();
foreach ($masterSlides as $masterSlide) {
$this->writeOverrideContentType($objWriter, '/ppt/theme/theme' . $masterSlide['masterid'] . '.xml', 'application/vnd.openxmlformats-officedocument.theme+xml');
}
// Presentation
$this->writeOverrideContentType($objWriter, '/ppt/presentation.xml', 'application/vnd.openxmlformats-officedocument.presentationml.presentation.main+xml');
// PptProps
$this->writeOverrideContentType($objWriter, '/ppt/presProps.xml', 'application/vnd.openxmlformats-officedocument.presentationml.presProps+xml');
$this->writeOverrideContentType($objWriter, '/ppt/tableStyles.xml', 'application/vnd.openxmlformats-officedocument.presentationml.tableStyles+xml');
$this->writeOverrideContentType($objWriter, '/ppt/viewProps.xml', 'application/vnd.openxmlformats-officedocument.presentationml.viewProps+xml');
// DocProps
$this->writeOverrideContentType($objWriter, '/docProps/app.xml', 'application/vnd.openxmlformats-officedocument.extended-properties+xml');
$this->writeOverrideContentType($objWriter, '/docProps/core.xml', 'application/vnd.openxmlformats-package.core-properties+xml');
$this->writeOverrideContentType($objWriter, '/docProps/custom.xml', 'application/vnd.openxmlformats-officedocument.custom-properties+xml');
// Slide masters
$masterSlides = $parentWriter->getLayoutPack()->getMasterSlides();
foreach ($masterSlides as $masterSlide) {
$this->writeOverrideContentType($objWriter, '/ppt/slideMasters/slideMaster' . $masterSlide['masterid'] . '.xml', 'application/vnd.openxmlformats-officedocument.presentationml.slideMaster+xml');
}
// Slide layouts
$slideLayouts = $parentWriter->getLayoutPack()->getLayouts();
$numSlideLayouts = count($slideLayouts);
for ($i = 0; $i < $numSlideLayouts; ++$i) {
$this->writeOverrideContentType($objWriter, '/ppt/slideLayouts/slideLayout' . ($i + 1) . '.xml', 'application/vnd.openxmlformats-officedocument.presentationml.slideLayout+xml');
}
// Slides
$slideCount = $pPhpPresentation->getSlideCount();
for ($i = 0; $i < $slideCount; ++$i) {
$this->writeOverrideContentType($objWriter, '/ppt/slides/slide' . ($i + 1) . '.xml', 'application/vnd.openxmlformats-officedocument.presentationml.slide+xml');
if ($pPhpPresentation->getSlide($i)->getNote()->getShapeCollection()->count() > 0) {
$this->writeOverrideContentType($objWriter, '/ppt/notesSlides/notesSlide' . ($i + 1) . '.xml', 'application/vnd.openxmlformats-officedocument.presentationml.notesSlide+xml');
}
}
// Add layoutpack content types
$otherRelations = $parentWriter->getLayoutPack()->getMasterSlideRelations();
foreach ($otherRelations as $otherRelation) {
if (strpos($otherRelation['target'], 'http://') !== 0 && $otherRelation['contentType'] != '') {
$this->writeOverrideContentType($objWriter, '/ppt/slideMasters/' . $otherRelation['target'], $otherRelation['contentType']);
}
}
$otherRelations = $parentWriter->getLayoutPack()->getThemeRelations();
foreach ($otherRelations as $otherRelation) {
if (strpos($otherRelation['target'], 'http://') !== 0 && $otherRelation['contentType'] != '') {
$this->writeOverrideContentType($objWriter, '/ppt/theme/' . $otherRelation['target'], $otherRelation['contentType']);
}
}
$otherRelations = $parentWriter->getLayoutPack()->getLayoutRelations();
foreach ($otherRelations as $otherRelation) {
if (strpos($otherRelation['target'], 'http://') !== 0 && $otherRelation['contentType'] != '') {
$this->writeOverrideContentType($objWriter, '/ppt/slideLayouts/' . $otherRelation['target'], $otherRelation['contentType']);
}
}
// Add media content-types
$aMediaContentTypes = array();
// GIF, JPEG, PNG
$aMediaContentTypes['gif'] = 'image/gif';
$aMediaContentTypes['jpg'] = 'image/jpeg';
$aMediaContentTypes['jpeg'] = 'image/jpeg';
$aMediaContentTypes['png'] = 'image/png';
foreach ($aMediaContentTypes as $key => $value) {
$this->writeDefaultContentType($objWriter, $key, $value);
}
// XLSX
$this->writeDefaultContentType($objWriter, 'xlsx', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
// Other media content types
$mediaCount = $parentWriter->getDrawingHashTable()->count();
for ($i = 0; $i < $mediaCount; ++$i) {
$extension = '';
$mimeType = '';
$shapeIndex = $parentWriter->getDrawingHashTable()->getByIndex($i);
if ($shapeIndex instanceof ShapeChart) {
// Chart content type
$this->writeOverrideContentType($objWriter, '/ppt/charts/chart' . $shapeIndex->getImageIndex() . '.xml', 'application/vnd.openxmlformats-officedocument.drawingml.chart+xml');
} else {
if ($shapeIndex instanceof ShapeDrawing) {
//.........这里部分代码省略.........
示例5: writePart
//.........这里部分代码省略.........
case Alignment::HORIZONTAL_CENTER:
$objWriter->writeAttribute('fo:text-align', 'center');
break;
case Alignment::HORIZONTAL_JUSTIFY:
$objWriter->writeAttribute('fo:text-align', 'justify');
break;
case Alignment::HORIZONTAL_DISTRIBUTED:
$objWriter->writeAttribute('fo:text-align', 'justify');
break;
default:
$objWriter->writeAttribute('fo:text-align', 'left');
break;
}
$objWriter->endElement();
$objWriter->endElement();
}
}
// Style : Text : Font
if (!empty($this->arrStyleTextFont)) {
foreach ($this->arrStyleTextFont as $key => $item) {
// style:style
$objWriter->startElement('style:style');
$objWriter->writeAttribute('style:name', 'T_' . $key);
$objWriter->writeAttribute('style:family', 'text');
// style:text-properties
$objWriter->startElement('style:text-properties');
$objWriter->writeAttribute('fo:color', '#' . $item->getColor()->getRGB());
$objWriter->writeAttribute('fo:font-family', $item->getName());
$objWriter->writeAttribute('fo:font-size', $item->getSize() . 'pt');
// @todo : fo:font-style
if ($item->isBold()) {
$objWriter->writeAttribute('fo:font-weight', 'bold');
}
// @todo : style:text-underline-style
$objWriter->endElement();
$objWriter->endElement();
}
}
$objWriter->endElement();
//===============================================
// Body
//===============================================
// office:body
$objWriter->startElement('office:body');
// office:presentation
$objWriter->startElement('office:presentation');
// Write slides
$slideCount = $pPhpPresentation->getSlideCount();
$this->shapeId = 0;
for ($i = 0; $i < $slideCount; ++$i) {
$pSlide = $pPhpPresentation->getSlide($i);
$objWriter->startElement('draw:page');
$name = $pSlide->getName();
if (!is_null($name)) {
$objWriter->writeAttribute('draw:name', $name);
}
$objWriter->writeAttribute('draw:master-page-name', 'Standard');
$objWriter->writeAttribute('draw:style-name', 'stylePage' . $i);
// Images
$shapes = $pSlide->getShapeCollection();
foreach ($shapes as $shape) {
// Increment $this->shapeId
++$this->shapeId;
// Check type
if ($shape instanceof RichText) {
$this->writeShapeTxt($objWriter, $shape);
} elseif ($shape instanceof Table) {
$this->writeShapeTable($objWriter, $shape);
} elseif ($shape instanceof Line) {
$this->writeShapeLine($objWriter, $shape);
} elseif ($shape instanceof Chart) {
$this->writeShapeChart($objWriter, $shape);
} elseif ($shape instanceof AbstractDrawing) {
$this->writeShapePic($objWriter, $shape);
} elseif ($shape instanceof Group) {
$this->writeShapeGroup($objWriter, $shape);
}
}
// Slide Note
if ($pSlide->getNote() instanceof Note) {
$this->writeSlideNote($objWriter, $pSlide->getNote());
}
$objWriter->endElement();
}
if ($pPhpPresentation->getPresentationProperties()->isLoopContinuouslyUntilEsc()) {
$objWriter->startElement('presentation:settings');
$objWriter->writeAttribute('presentation:endless', 'true');
$objWriter->writeAttribute('presentation:pause', 'P0s');
$objWriter->writeAttribute('presentation:mouse-visible', 'false');
$objWriter->endElement();
}
// > office:presentation
$objWriter->endElement();
// > office:body
$objWriter->endElement();
// > office:document-content
$objWriter->endElement();
// Return
return $objWriter->getData();
}
示例6: testGetSlideException
/**
* Test get slide exception
*
* @expectedException Exception
* @expectedExceptionMessage Slide index is out of bounds.
*/
public function testGetSlideException()
{
$object = new PhpPresentation();
$object->getSlide(1);
}
示例7: save
//.........这里部分代码省略.........
foreach ($masterSlides as $masterSlide) {
// Add themes to ZIP file
$objZip->addFromString('ppt/theme/_rels/theme' . $masterSlide['masterid'] . '.xml.rels', $wPartRels->writeThemeRelationships($masterSlide['masterid']));
$objZip->addFromString('ppt/theme/theme' . $masterSlide['masterid'] . '.xml', $wPartTheme->writeTheme($masterSlide['masterid']));
// Add slide masters to ZIP file
$objZip->addFromString('ppt/slideMasters/_rels/slideMaster' . $masterSlide['masterid'] . '.xml.rels', $wPartRels->writeSlideMasterRelationships($masterSlide['masterid']));
$objZip->addFromString('ppt/slideMasters/slideMaster' . $masterSlide['masterid'] . '.xml', $masterSlide['body']);
}
// Add slide layouts to ZIP file
$slideLayouts = $this->getLayoutPack()->getLayouts();
foreach ($slideLayouts as $key => $layout) {
$objZip->addFromString('ppt/slideLayouts/_rels/slideLayout' . $key . '.xml.rels', $wPartRels->writeSlideLayoutRelationships($key, $layout['masterid']));
$objZip->addFromString('ppt/slideLayouts/slideLayout' . $key . '.xml', utf8_encode($layout['body']));
}
// Add layoutpack relations
$otherRelations = $this->getLayoutPack()->getMasterSlideRelations();
foreach ($otherRelations as $otherRelation) {
if (strpos($otherRelation['target'], 'http://') !== 0) {
$objZip->addFromString($this->absoluteZipPath('ppt/slideMasters/' . $otherRelation['target']), $otherRelation['contents']);
}
}
$otherRelations = $this->getLayoutPack()->getThemeRelations();
foreach ($otherRelations as $otherRelation) {
if (strpos($otherRelation['target'], 'http://') !== 0) {
$objZip->addFromString($this->absoluteZipPath('ppt/theme/' . $otherRelation['target']), $otherRelation['contents']);
}
}
$otherRelations = $this->getLayoutPack()->getLayoutRelations();
foreach ($otherRelations as $otherRelation) {
if (strpos($otherRelation['target'], 'http://') !== 0) {
$objZip->addFromString($this->absoluteZipPath('ppt/slideLayouts/' . $otherRelation['target']), $otherRelation['contents']);
}
}
// Add presentation to ZIP file
$objZip->addFromString('ppt/presentation.xml', $wPartPresentation->writePresentation($this->presentation));
// Add slides (drawings, ...) and slide relationships (drawings, ...)
for ($i = 0; $i < $this->presentation->getSlideCount(); ++$i) {
$oSlide = $this->presentation->getSlide($i);
// Add slide
$objZip->addFromString('ppt/slides/_rels/slide' . ($i + 1) . '.xml.rels', $wPartRels->writeSlideRelationships($oSlide));
$objZip->addFromString('ppt/slides/slide' . ($i + 1) . '.xml', $wPartSlide->writeSlide($oSlide));
// Add note slide
if ($oSlide->getNote()->getShapeCollection()->count() > 0) {
$objZip->addFromString('ppt/notesSlides/notesSlide' . ($i + 1) . '.xml', $wPartSlide->writeNote($oSlide->getNote()));
}
// Add background image slide
$oBkgImage = $oSlide->getBackground();
if ($oBkgImage instanceof Image) {
$objZip->addFromString('ppt/media/' . $oBkgImage->getIndexedFilename($i), file_get_contents($oBkgImage->getPath()));
}
}
// Add media
for ($i = 0; $i < $this->getDrawingHashTable()->count(); ++$i) {
$shape = $this->getDrawingHashTable()->getByIndex($i);
if ($shape instanceof DrawingShape) {
$imagePath = $shape->getPath();
if (strpos($imagePath, 'zip://') !== false) {
$imagePath = substr($imagePath, 6);
$imagePathSplitted = explode('#', $imagePath);
$imageZip = new \ZipArchive();
$imageZip->open($imagePathSplitted[0]);
$imageContents = $imageZip->getFromName($imagePathSplitted[1]);
$imageZip->close();
unset($imageZip);
} else {
$imageContents = file_get_contents($imagePath);
}
$objZip->addFromString('ppt/media/' . str_replace(' ', '_', $shape->getIndexedFilename()), $imageContents);
} elseif ($shape instanceof MemoryDrawingShape) {
ob_start();
call_user_func($shape->getRenderingFunction(), $shape->getImageResource());
$imageContents = ob_get_contents();
ob_end_clean();
$objZip->addFromString('ppt/media/' . str_replace(' ', '_', $shape->getIndexedFilename()), $imageContents);
} elseif ($shape instanceof ChartShape) {
$objZip->addFromString('ppt/charts/' . $shape->getIndexedFilename(), $wPartChart->writeChart($shape));
// Chart relations?
if ($shape->hasIncludedSpreadsheet()) {
$objZip->addFromString('ppt/charts/_rels/' . $shape->getIndexedFilename() . '.rels', $wPartRels->writeChartRelationships($shape));
$objZip->addFromString('ppt/embeddings/' . $shape->getIndexedFilename() . '.xlsx', $wPartChart->writeSpreadsheet($this->presentation, $shape, $pFilename . '.xlsx'));
}
}
}
// Close file
if ($objZip->close() === false) {
throw new \Exception("Could not close zip file {$pFilename}.");
}
// If a temporary file was used, copy it to the correct file stream
if ($originalFilename != $pFilename) {
if (copy($pFilename, $originalFilename) === false) {
throw new \Exception("Could not copy temporary zip file {$pFilename} to {$originalFilename}.");
}
if (@unlink($pFilename) === false) {
throw new \Exception('The file ' . $pFilename . ' could not be removed.');
}
}
} else {
throw new \Exception("PhpPresentation object unassigned.");
}
}