我尝试在codeigniter框架中安装phppresentation库。但是在codeigniter中不能使用命名空间。那么如何集成呢?
发布于 2017-03-09 23:39:52
这可能不是一个“最佳实践”示例,但我在PHPPresentation Packagist page上获得了“入门”示例,以便在CI 3.1.3中工作。
我使用CI手册中描述的默认方式使用composer。
应用程序目录和系统目录在根目录的上一级。
composer.json文件位于应用程序目录中。
将以下内容从打包列表页面剪切粘贴到composer.json中,然后运行composer update将其保存到应用程序/供应商/phpoffice中。
{
"require": {
"phpoffice/phppresentation": "dev-master"
}
}在应用程序/库中创建了Ppt_stuff.php。剪切-n-粘贴入门示例到文件中。我必须添加类名和函数make_ppt。还使用realpath('.')修复了setPath和保存函数的路径名。
<?php defined('BASEPATH') OR exit('No direct script access allowed');
use PhpOffice\PhpPresentation\PhpPresentation;
use PhpOffice\PhpPresentation\IOFactory;
use PhpOffice\PhpPresentation\Style\Color;
use PhpOffice\PhpPresentation\Style\Alignment;
class Ppt_stuff {
public function make_ppt() {
$objPHPPowerPoint = new PhpPresentation();
// Create slide
$currentSlide = $objPHPPowerPoint->getActiveSlide();
// Create a shape (drawing)
$shape = $currentSlide->createDrawingShape();
$shape->setName('PHPPresentation logo')
->setDescription('PHPPresentation logo')
->setPath(realpath('.') . '/../application/vendor/phpoffice/phppresentation/samples/resources/phppowerpoint_logo.gif')
->setHeight(36)
->setOffsetX(10)
->setOffsetY(10);
$shape->getShadow()->setVisible(true)
->setDirection(45)
->setDistance(10);
// Create a shape (text)
$shape = $currentSlide->createRichTextShape()
->setHeight(300)
->setWidth(600)
->setOffsetX(170)
->setOffsetY(180);
$shape->getActiveParagraph()->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER);
$textRun = $shape->createTextRun('Thank you for using PHPPresentation!');
$textRun->getFont()->setBold(true)
->setSize(60)
->setColor(new Color('FFE06B20'));
$oWriterPPTX = IOFactory::createWriter($objPHPPowerPoint, 'PowerPoint2007');
$oWriterPPTX->save(realpath('.') . "/downloads/sample.pptx");
$oWriterODP = IOFactory::createWriter($objPHPPowerPoint, 'ODPresentation');
$oWriterODP->save(realpath('.') . "/downloads/sample.odp");
}
}在根目录中创建了/downloads目录。
已将此功能添加到主控制器。
public function use_presentation() {
// load library
$this->load->library('Ppt_stuff');
// call make_ppt
$this->ppt_stuff->make_ppt();
return;
}转到http://localhost/home/use_presentation,它在/downloads中创建了sample.pptx和sample.odp。
当我打开它们时,Powerpoint 2010抱怨并提出要修复它们。
https://stackoverflow.com/questions/42691801
复制相似问题