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

TextRun in addTitle causes TOC error. #1625

Open
markmorris opened this issue May 2, 2019 · 2 comments
Open

TextRun in addTitle causes TOC error. #1625

markmorris opened this issue May 2, 2019 · 2 comments

Comments

@markmorris
Copy link

markmorris commented May 2, 2019

This is:

  • [* ] a bug report

So I've been having an issue for a while regarding tabs in titles. Tabs do not work at all, looking deeper into the code I have seen that titles actually support TextRuns. Using a TextRun in the title causes the tab issue to go away. However, the docx file now errors on open (although the content is all there) and TOC has issues (Text missing).

How to Reproduce

<?php

$titleText = new TextRun();
$titleText->addText("Hello \t");
$titleText->addText('Some other text');
$sceneSection->addTitle($titleText, 1);
@koolkiizz
Copy link

koolkiizz commented Feb 10, 2020

This work for me:
PhpOffice\PhpWord\Writer\Word2007\Element\TOC
On line 100, change that line to:
`
if (get_class($title->getText()) === 'PhpOffice\PhpWord\Element\TextRun') {

        $textRunElements = $title->getText()->getElements();
        $uploadedText = '';
        foreach ($textRunElements as $textRunElement) {
            $uploadedText .= $textRunElement->getText();
            $uploadedText .= ' ';
        }
        $this->writeText($uploadedText);
    } else {
        $this->writeText($title->getText());
    }`

Sorry, can't comment as code syntax :(

@zsimple
Copy link

zsimple commented Mar 12, 2020

Thanks @koolkiizz , you saved me tons of time.
my php version reports a warning when a string passed to get_class, so I used gettype, not good but works for me now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants