Skip to content

Can't read the section heading , only read and return the text in section, replace section with new line<br> #2486

@malyk-waqar

Description

@malyk-waqar

Describe the Bug

A clear and concise description of what the bug is.

Steps to Reproduce

Please provide a code sample that reproduces the issue.

$phpWord = IOFactory::load($wordFile);
$wordText = '';

 foreach ($phpWord->getSections() as $section) { $elements = $section->getElements(); $numElements = count($elements); foreach ($elements as $key => $element) { if ($element instanceof \PhpOffice\PhpWord\Element\TextRun) { foreach ($element->getElements() as $textElement) { if ($textElement instanceof \PhpOffice\PhpWord\Element\Text) { $wordText .= $textElement->getText(); } } } elseif ($element instanceof \PhpOffice\PhpWord\Element\Text) { $wordText .= $element->getText(); } // Add a line break if it's not the last element in the section. if ($key < $numElements - 1) { $wordText .= PHP_EOL; } } } $formattedText = $wordText; 

Expected Behavior

A clear and concise description of what you expected to happen.

Current Behavior

What is the current behavior?

Context

Please fill in your environment information:

  • PHP Version:
  • PHPWord Version:

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions