Skip to content
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

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

Closed
malyk-waqar opened this issue Oct 16, 2023 · 2 comments
Milestone

Comments

@malyk-waqar
Copy link

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:
@lebuhorskiy
Copy link

To add a line break you need to pass </w:t><w:br/><w:t> instead PHP_EOL
I saw this in #2522
I hope this will be added in the next version

@Progi1984
Copy link
Member

Fixed in #2522

@Progi1984 Progi1984 added this to the 2.0.0 milestone Jan 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

3 participants