发布于 2023-10-19 00:44:51 浏览 295 次
composer require phpoffice/phpword
require_once 'vendor/autoload.php';
use PhpOffice\PhpWord\IOFactory;
// 指定要读取的 Word 文档路径
$filePath = 'path/to/your/word/document.docx';
// 使用 IOFactory 加载 Word 文档
$phpWord = IOFactory::load($filePath);
// 获取文档中的所有段落,并输出其文本内容
$paragraphs = $phpWord->getSections()[0]->getElements()[0]->getElements();
foreach ($paragraphs as $paragraph) {
echo $paragraph->getText() . "\n";
}