这是我目前的代码
$phpWord = \PhpOffice\PhpWord\IOFactory::load($source);
$sections = $phpWord->getSections();
foreach ($sections as $s) {
$els = $s->getElements();
foreach ($els as $e) {
switch (get_class($element)) {
case 'PhpOffice\PhpWord\Element\TextRun':
$this->logger->debug("TextRun");
$this->getTextFromTextRun($element);
break;
case 'PhpOffice\PhpWord\Element\Table':
$this->logger->debug("Table");
$this->iterateOverRows($element);
break;
}
}
}
private function getTextFromTextRun($element) {
for ($index = 0; $index < $element->countElements(); $index++) {
$textRunElement = $element->getElement($index);
$text = $textRunElement->getText();
if (strlen($text) > 0) {
$this->logger->debug("TextRun Text: " . $text);
}
}
}
private function iterateOverRows($table) {
$rows = $table->getRows();
foreach ($rows as $row) {
foreach ($row->getCells() as $cell) {
// What to do here???
}
}
}
我不知道如何从单元格中获取内容?
这些是单元对象中可用的 getter 方法:
获取评论范围结束
获取评论范围开始
获取文档部分
获取文档部分ID
获取元素
获取元素Id
获取元素索引
获取元素
获取嵌套级别
获取父级
获取PHPWord
获取关系Id
获取SectionId
获取样式
获取轨迹更改
获取宽度
阿晨1998