{"id":19166685,"url":"https://github.com/lmsail/php_exportppt","last_synced_at":"2026-06-17T03:31:55.610Z","repository":{"id":227975506,"uuid":"772413921","full_name":"lmsail/php_exportppt","owner":"lmsail","description":"`php`使用`PhpOffice`导出`ppt`","archived":false,"fork":false,"pushed_at":"2024-04-21T06:05:22.000Z","size":545,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-22T23:24:12.963Z","etag":null,"topics":["php","phpoffice","ppt"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lmsail.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2024-03-15T06:26:14.000Z","updated_at":"2024-04-21T06:05:25.000Z","dependencies_parsed_at":"2024-04-21T07:23:13.341Z","dependency_job_id":"2d7ff733-c777-4324-96e4-40e52bcfad77","html_url":"https://github.com/lmsail/php_exportppt","commit_stats":null,"previous_names":["lmsail/php_exportppt"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/lmsail/php_exportppt","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lmsail%2Fphp_exportppt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lmsail%2Fphp_exportppt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lmsail%2Fphp_exportppt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lmsail%2Fphp_exportppt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lmsail","download_url":"https://codeload.github.com/lmsail/php_exportppt/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lmsail%2Fphp_exportppt/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34433085,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-17T02:00:05.408Z","response_time":127,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["php","phpoffice","ppt"],"created_at":"2024-11-09T09:33:59.124Z","updated_at":"2026-06-17T03:31:55.594Z","avatar_url":"https://github.com/lmsail.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# php_exportppt\n`php`使用`PhpOffice`导出`ppt`\n\n```php\n\u003c?php\n\nrequire './vendor/autoload.php';\n\nuse PhpOffice\\PhpPresentation\\PhpPresentation;\nuse PhpOffice\\PhpPresentation\\DocumentLayout;\nuse PhpOffice\\PhpPresentation\\IOFactory;\nuse PhpOffice\\PhpPresentation\\Style\\Color;\nuse PhpOffice\\PhpPresentation\\Style\\Alignment;\nuse PhpOffice\\PhpPresentation\\Style\\Background;\nuse PhpOffice\\PhpPresentation\\Shape\\Drawing;\nuse PhpOffice\\PhpPresentation\\Slide\\Background\\Image;\n\nclass PhpOffice\n{\n    private const WIDTH = 1600;\n    \n    private const HEIGHT = 1000;\n    \n    private const LINE = '------------------------------------------------------------------------------';\n    \n    /**\n     * 创建第一页或最后一页\n     */ \n    public function createHeaderOrFooter($objPHPPowerPoint, string $title, string $imagepath, string $subtitle = '') \n    {\n        $slide = $objPHPPowerPoint-\u003ecreateSlide();\n        \n        # 创建背景图\n        $slide-\u003esetBackground((new Image())-\u003esetPath($imagepath));\n        \n        # 创建标题文本\n        $this-\u003ecreateText($slide, $title, 60, self::WIDTH, 160, 250, Alignment::HORIZONTAL_LEFT)-\u003esetBold(true)-\u003esetSize(40)-\u003esetColor(new Color(Color::COLOR_BLACK));\n        \n        # 副标题文本\n        if (!empty($subtitle)) {\n            $this-\u003ecreateText($slide, $subtitle, 60, self::WIDTH, 160, 350, Alignment::HORIZONTAL_LEFT)-\u003esetBold(false)-\u003esetSize(25)-\u003esetColor(new Color('FF666666'));\n        }\n        \n        # 创建小程序码\n        $this-\u003ecreateImage($slide, './images/logo.png', 200, 200, 160, 550);\n        \n        # 创建说明文本\n        $this-\u003ecreateText($slide, '扫码查看小程序', 60, 200, 160, 760)-\u003esetSize(16)-\u003esetColor(new Color('FF666666'));\n    }\n    \n    /**\n     * 绘制文本\n     */ \n    private function createText($slide, string $text, int $height, int $width, int $x, int $y, string $position = Alignment::HORIZONTAL_CENTER) \n    {\n        $shape = $slide-\u003ecreateRichTextShape()-\u003esetHeight($height)-\u003esetWidth($width)-\u003esetOffsetX($x)-\u003esetOffsetY($y);\n        $shape-\u003egetActiveParagraph()-\u003egetAlignment()-\u003esetHorizontal($position);\n        $textRun = $shape-\u003ecreateTextRun()-\u003esetText($text);\n        return $textRun-\u003egetFont();\n    }\n    \n    /**\n     * 绘制图片\n     */ \n    private function createImage($slide, string $imagepath, int $height, int $width, int $x, int $y) \n    {\n        $shape = $slide-\u003ecreateDrawingShape();\n        $shape-\u003esetPath($imagepath)-\u003esetResizeProportional(false)-\u003esetHeight($height)-\u003esetWidth($width)-\u003esetOffsetX($x)-\u003esetOffsetY($y);\n        return $shape;\n    }\n    \n    /**\n     * 绘制产品介绍文本\n     */ \n    private function createProductText($slide, string $title, int $y, string $color = 'FF8C8C8C') {\n        $this-\u003ecreateText($slide, $title, 40, 720, 740, $y, Alignment::HORIZONTAL_LEFT)-\u003esetSize(18)-\u003esetColor(new Color($color));\n    }\n    \n    /**\n     * 创建商品详情页\n     */ \n    public function createProductDetail($slide, $mainImage, $images) \n    {\n        # 左边商品图片组：1张大图，底下三个小图  \n        $this-\u003ecreateImage($slide, $mainImage, 660, 660, 40, 40);\n        \n        # 大图下的3张小图\n        $x = 40; $y = 720;\n        foreach ($images as $image) {\n            $this-\u003ecreateImage($slide, $image, 210, 210, $x, $y);\n            $x += 225;\n        }\n        \n        # 右侧文本\n        $this-\u003ecreateProductText($slide, '商品ID：304513', 40 * 1);\n        $this-\u003ecreateProductText($slide, '瑷露德玛 芦荟紧致滋养水120ml', 40 * 2, 'FFB6712D');\n        \n        $this-\u003ecreateProductText($slide, self::LINE, 40 * 3, 'FFCCCCCC'); // 分隔符\n        \n        $this-\u003ecreateProductText($slide, '商品属性', 40 * 4, 'FFB6712D');\n        $this-\u003ecreateProductText($slide, '商品毛重：140.00g', 40 * 5);\n        $this-\u003ecreateProductText($slide, '商品产地：中国大陆', 40 * 6);\n        $this-\u003ecreateProductText($slide, '特色功能：防汗', 40 * 7);\n        $this-\u003ecreateProductText($slide, '佩戴方式：入耳式', 40 * 8);\n        $this-\u003ecreateProductText($slide, '振膜类型：单动铁', 40 * 9);\n        \n        $this-\u003ecreateProductText($slide, '商品价格', 40 * 10, 'FFB6712D');\n        $this-\u003ecreateProductText($slide, '装箱数：12   集采起订量：12', 40 * 11);\n        $this-\u003ecreateProductText($slide, '集采价：¥140.4    电商价：¥149.00', 40 * 12);\n        $this-\u003ecreateProductText($slide, '代发价：¥144.0 ', 40 * 13);\n        \n        $this-\u003ecreateProductText($slide, '商品卖点', 40 * 14, 'FFB6712D');\n        $this-\u003ecreateProductText($slide, '①采用专利技术12小时完成库拉索芦荟从鲜叶到成品的加', 40 * 15);\n        $this-\u003ecreateProductText($slide, '②芦荟精粹活性高，基础补水更尽兴，肌底渗透强', 40 * 16);\n        $this-\u003ecreateProductText($slide, '③奢宠滋养呵护，肌肤整天都饱满莹润水嘟嘟', 40 * 17);\n        $this-\u003ecreateProductText($slide, '④添加黄金胜肽肌肽，深层渗透，修护老化脆弱肌肤', 40 * 18);\n        $this-\u003ecreateProductText($slide, '⑤活细胞元气，提升肌肤弹性，让肌肤饱满如婴儿肌', 40 * 19);\n    }\n    \n    public function index()\n    {\n        // 1.创建ppt对象\n        $objPHPPowerPoint = new PhpPresentation();\n        \n        # 2.自定义幻灯片尺寸\n        $objPHPPowerPoint-\u003egetLayout()-\u003esetCX(self::WIDTH, DocumentLayout::UNIT_PIXEL)-\u003esetCY(self::HEIGHT, DocumentLayout::UNIT_PIXEL);\n\n        // 3.设置属性\n        $objPHPPowerPoint-\u003egetDocumentProperties()-\u003esetCreator('PHPOffice')\n            -\u003esetLastModifiedBy('PHPPresentation Team')\n            -\u003esetTitle('Sample 02 Title')\n            -\u003esetSubject('Sample 02 Subject')\n            -\u003esetDescription('Sample 02 Description')\n            -\u003esetKeywords('office 2007 openxml libreoffice odt php')\n            -\u003esetCategory('Sample Category');\n\n        // 4.删除第一页(多页最好删除)\n        $objPHPPowerPoint-\u003eremoveSlideByIndex(0);\n        \n        # 第一页\n        $this-\u003ecreateHeaderOrFooter($objPHPPowerPoint, '女神节心意礼品方案', './images/bg.jpeg');\n\n        //根据需求 调整for循环\n        for ($i = 1; $i \u003c= 3; $i++) {\n            \n            //创建幻灯片并添加到这个演示中\n            $slide = $objPHPPowerPoint-\u003ecreateSlide();\n            \n            # 构建产品介绍页\n            $this-\u003ecreateProductDetail($slide, './images/1.png', ['./images/1.png', './images/2.png', './images/1.png']);\n        }\n        \n        # 最后一页\n        $this-\u003ecreateHeaderOrFooter($objPHPPowerPoint, '谢谢您的观看', './images/bg.jpeg');\n\n        $oWriterPPTX = IOFactory::createWriter($objPHPPowerPoint, 'PowerPoint2007');\n        $url = './upload/' . time() . \".pptx\";\n        $oWriterPPTX-\u003esave($url);\n        \n        download($url);\n    }\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flmsail%2Fphp_exportppt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flmsail%2Fphp_exportppt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flmsail%2Fphp_exportppt/lists"}