用于读取、生成和操作 Microsoft Office 文档,例如 Word、Excel、PowerPoint 等

1.0 2023-10-17 01:08 UTC

This package is not auto-updated.

Last update: 2024-05-01 02:08:41 UTC


README

Office 提供了一系列的工具和库,用于读取、生成和操作 Microsoft Office 文档,例如 Word、Excel、PowerPoint 等。使用 PHP Office,我们可以轻松地实现很多以前不能操作或难以处理的 Office 文档相关的功能,因此在开发 Web 应用程序时,PHP Office 是一个非常有用的工具库。 例如,在我们需要将 Excel 数据导入到数据库中时,我们可以使用 Phpspreadsheet 库来处理 Excel 文件。这个库提供了丰富的功能,例如读取 Excel 数据、合并或分割 Excel 文件、转换文件格式等。

安装

s "require": {

    "laoqianjunzi/office":"1.*"

},

### Excel 

use office\Excel\IOFactory; // 打开 Excel 文件 $reader = IOFactory::createReader('Xlsx'); $spreadsheet = $reader->load('example.xlsx'); // 获取工作表和行数 $worksheet = $spreadsheet->getActiveSheet(); $highestRow = $worksheet->getHighestRow();


### Word

use office\Word\TemplateProcessor;

$template = new TemplateProcessor('template.docx'); $template->setValue('content', $pdfText); $template->saveAs('result.docx');


### PowerPoint

//创建类 $powerPoint = new PowerPoint(); //无论首次还是追加都需要设置母版 $powerPoint->createMaster(); //第一次的时候可能需要单独的一个头部信息 $powerPoint->createHeader($dataHeader); //循环调用此方法,每调用一次增加一个PPT页面 $powerPoint->createCotent($data); //判断所有PPT页面都加完了调用此方法 $powerPoint->createFooter(); //保存或者追加用此方法,里面判断不存在文件时用自带的save方法,否则追加,追加方法看后面 $powerPoint->appendSave($file);