【发布时间】:2017-11-19 23:51:15
【问题描述】:
如何在php中从Doc文件中获取内容
我在 Yii2 中使用PHPOffice/PHPWord。
此代码不起作用:(我的文档文件是 UTF8)
$phpWord = \PhpOffice\PhpWord\IOFactory::load($filename, 'MsDoc');
$sections = $phpWord->getSections();
foreach ($sections as $key => $value) {
$sectionElement = $value->getElements();
foreach ($sectionElement as $elementKey => $elementValue) {
if ($elementValue instanceof \PhpOffice\PhpWord\Element\TextRun) {
$secondSectionElement = $elementValue->getElements();
foreach ($secondSectionElement as $secondSectionElementKey => $secondSectionElementValue) {
if ($secondSectionElementValue instanceof \PhpOffice\PhpWord\Element\Text) {
echo $secondSectionElementValue->getText() . '<br/>';
}
}
}
}
}
我需要从文档文件中获取内容(标题,...)
【问题讨论】:
标签: php yii2 doc phpword phpoffice