Проблема следующая, выдает ошибку при парсинге docx файла, где есть разрывы между страницами:
Fatal error: Uncaught Error: Call to undefined method PhpOffice\PhpWord\Element\TextBreak::getText() in D:\OSPanel\domains\ ...
вот код:
$file = ROOT . '\upload\doc\iz1.docx';
$objReaderWordX = \PhpOffice\PhpWord\IOFactory::createReader('Word2007');
$phpWord = $objReaderWordX->load( $file );
foreach ( $phpWord->getSections() as $section ) {
$arr = $section->getElements();
foreach ( $arr as $valuEx ) {
if ( get_class( $valuEx ) == 'PhpOffice\PhpWord\Element\TextRun' ) {
foreach ( $valuEx->getElements() as $textEx ) {
print_r( $textEx->getText() );
}
} else if ( get_class( $valuEx ) === 'PhpOffice\PhpWord\Element\PageBreak' ) {
echo '============= 2 Разрыв страницы =========================';
} else if ( get_class( $valuEx ) === 'PhpOffice\PhpWord\Element\TextBreak' ) {
echo '<br>';
} else if ( get_class( $valuEx ) === 'PhpOffice\PhpWord\Element\Table' ) {
echo '<table border="2px">';
$rows = $valuEx->getRows();
foreach ( $rows as $row ) {
echo '<tr>';
$cells = $row->getCells();
foreach ( $cells as $cell ) {
echo '<td style="width:'. $cell->getWidth() .'; height:20p">';
$cElements = $cell->getElements();
foreach ( $cElements as $cElem ) {
if ( get_class( $cElem ) === 'PhpOffice\PhpWord\Element\Text' ) {
print_r( $cElem->getText() );
} else if ( get_class( $cElem ) === 'PhpOffice\PhpWord\Element\TextRun' ) {
foreach ( $cElem->getElements() as $cElemText ) {
print_r( $cElemText->getText() );
}
}
}
echo '</td>';
}
echo '</tr>';
}
echo '</table>';
}
}
}