1 回答
TA贡献2037条经验 获得超6个赞
已经在这里解决了这个问题:
private function iterateOverRows($table) {
$rows = $table->getRows();
foreach ($rows as $row) {
foreach ($row->getCells() as $cell) {
$els = $cell->getElements();
foreach ($els as $e) {
$this->switchElements($e);
}
}
}
}
private function switchElements($element) {
switch (get_class($element)) {
case 'PhpOffice\PhpWord\Element\TextRun':
$this->getTextFromTextRun($element);
break;
case 'PhpOffice\PhpWord\Element\Table':
$this->iterateOverRows($element);
break;
default:
break;
}
}
private function getTextFromTextRun($element) {
for ($index = 0; $index < $element->countElements(); $index++) {
$textRunElement = $element->getElement($index);
switch (get_class($textRunElement)) {
case 'PhpOffice\PhpWord\Element\Text':
case 'PhpOffice\PhpWord\Element\TextRun':
$text = $textRunElement->getText();
if (strlen($text) > 0) {
$this->logger->debug("Text: " . $text);
$this->getFont($textRunElement);
}
break;
case 'PhpOffice\PhpWord\Element\TextBreak':
break;
default:
break;
}
}
}
- 1 回答
- 0 关注
- 113 浏览
添加回答
举报