-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Call to undefined method PhpOffice\PhpWord\Element\TextBreak::getText() #1573
Comments
I am trying to read docx file, code: $df = $query1->filename;
if($query1->raw=="docx"){
$source = '../web/doc/'.$df.'';
$objReader = IOFactory::createReader('Word2007');
$phpWord = $objReader->load($source);
$body = '';
foreach ($phpWord->getSections() as $section) {
$arrays = $section->getElements();
$body .='<p>';
foreach ($arrays as $e) {
if(get_class($e) === 'PhpOffice\PhpWord\Element\TextBreak'){
$body .='<br>';
}else
if(get_class($e) === 'PhpOffice\PhpWord\Element\TextRun') {
foreach($e->getElements() as $text) {
//$font = $text->getFontStyle();
//$size = $font->getSize();
//$bold = $font->isBold() ? 'font-weight:700;' :'';
//$color = $font->getColor();
//if($font->isItalic()){
//$ital = 'italic';
//} else {$ital = '';};
//$fontFamily = $font->getName();
$body = $body.'<span style="float:left;font-size:14px;">'.$text->getText().'</span>';
}
}
if(get_class($e) === 'PhpOffice\PhpWord\Element\Text'){
$font = $e->getFontStyle();
$size = $font->getSize();
$bold = $font->isBold() ? 'font-weight:700;' :'';
$color = $font->getColor();
if($font->isItalic()){
$ital = 'italic';
} else {$ital = '';};
$fontFamily = $font->getName();
$body .='<span style="display:inline;text-align:left;font-style:'.$ital.';font-size:14px;font-family:'.$fontFamily .';'.$bold.'; color:#'.$color.';'.$line.'">';
$body .=$e->getText().'</span>';
}
if(get_class($e) === 'PhpOffice\PhpWord\Element\Image'){
$body .= '<div style="width:200px;height:150px; background:red;"></div>';
}
if(get_class($e) === 'PhpOffice\PhpWord\Element\Table') {
$body .= '<table border="2px">';
$rows = $e->getRows();
foreach($rows as $row) {
$body .= '<tr>';
$cells = $row->getCells();
foreach($cells as $cell) {
$body .= '<td style="width:'.$cell->getWidth().'">';
$celements = $cell->getElements();
foreach($celements as $celem) {
if(get_class($celem) === 'PhpOffice\PhpWord\Element\Text') {
$body .= $celem->getText();
}
else if(get_class($celem) === 'PhpOffice\PhpWord\Element\TextRun') {
foreach($celem->getElements() as $text) {
$body .= $text->getText();
}
}
}
$body .= '</td>';
}
$body .= '</tr>';
}
$body .= '</table>';
}
if (get_class($e)==='PhpOffice\PhpWord\Element\ListItem'){
$list = new \PhpOffice\PhpWord\Style\ListItem();
$listType .= $list->getListType();
if($listType === 7) {
$lts = '<ol>';
$lte = '</ol>';
}
else if($listType === 3) {
$lts = '<ul>';
$lte = '</ul>';
}
$body .='<ul style="font-size:14px; color:black; font-family:Times-New-Roman;>';
$ee = 'PhpOffice\PhpWord\Element\ListItem';
$obj = $e->getTextObject();
$body .='<li style="color:'.$color.';">';
if(get_class($obj)==='PhpOffice\PhpWord\Element\Text'){
$body .=$obj->getText();
}
$body .='</li>';
$body .='</ul>';
}
// else {
// $body .= $e->getText();
// }
}
$body .='</p>';
break;
}
} |
But I get an error, Call to undefined method PhpOffice\PhpWord\Element\TextBreak::getText() |
Do you have a complete stacktrace? I guess it fails when loading the document? |
Hi Troosan, I am also getting similar error with function getParagraphStyle() I am using following code: '; '; } }
} Code for calling above function: I have attached source file, please check and let me know if there is a solution. |
As there can be TextBreak inside TextRun, doing a for loop on TextRun and then applying getText from childs lead to try to call getText for TextBreak, and so lead to the error. For the second one, PageBreak is supposed to be a child of Section object. So that $ele1 can be a PageBreak and PageBreak is not having a method called getParagraphStyle |
This is:
Expected Behavior
Please describe the behavior you are expecting.
Current Behavior
What is the current behavior?
Failure Information
Please help provide information about the failure.
How to Reproduce
Please provide a code sample that reproduces the issue.
Context
The text was updated successfully, but these errors were encountered: