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

linebreak #384

Open
alimo2 opened this issue Sep 28, 2014 · 7 comments
Open

linebreak #384

alimo2 opened this issue Sep 28, 2014 · 7 comments

Comments

@alimo2
Copy link

alimo2 commented Sep 28, 2014

Hi,

How can i put long text with many line break in phpword?
is it possible to use str_replace function to replace " \r\n " with any meaningful xml tag?

//$text is long text with many linebreaks
$text = str_replace("\r\n",'<w:br/>',$text);
$section->addText($text);

Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

@alimo2
Copy link
Author

alimo2 commented Sep 29, 2014

no answer?

@alpha1125
Copy link

$text = explode("\r\n", $text);
foreach($text as $line) {
$section->addText($line);
}

@alimo2
Copy link
Author

alimo2 commented Sep 30, 2014

Yes I did it temporary in my case, but is there any way phpword detect line-breaks itself?

@simogeo
Copy link

simogeo commented Jun 15, 2015

See also #553 and #268 ....

I'm very surprised the addText() method does not handle this yet. It could be an optional parameter and implemented as follow (the code below is not tested and may not work !) :

    /**
     * Create a new Text Element
     *
     * @param string $text
     * @param mixed $fontStyle
     * @param mixed $paragraphStyle
     */
    public function __construct($text = null, $fontStyle = null, $paragraphStyle = null, $paragraphOnNewLine = null)
    {
       if(paragraphOnNewLine === null) {
        $this->setText($text);
        $paragraphStyle = $this->setParagraphStyle($paragraphStyle);
        $this->setFontStyle($fontStyle, $paragraphStyle);
       } else {
        $text = preg_match('~(*BSR_ANYCRLF)\R~', $text);
        foreach($text as $line) {
             $foo = new addText($line, $fontStyle, $paragraphStyle);
             $foo->setText($text);
             $paragraphStyle = $foo->setParagraphStyle($paragraphStyle);
             $foo->setFontStyle($fontStyle, $paragraphStyle);
       }
    }

I would argue that a similar need has been expressed using Template mechanism (see : #268).

@scalco19
Copy link

scalco19 commented Feb 7, 2016

there solutions to this issue , I have a similar problem

@1manfactory
Copy link

$text = "foo\nbar\nfoobar";
$section = $phpWord->addSection();
$textlines = explode("\n", $text);
foreach($textlines as $line) {
   $section->addText(htmlspecialchars($line));
}

this will insert a line break for each paragraph.
I don't get it why phpword makes it so complicated just to print a simple longer text with line breaks.

@github-actions
Copy link

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
If this is still an issue for you, please try to help by debugging it further and sharing your results.
Thank you for your contributions.

@github-actions github-actions bot added the Stale label Nov 18, 2022
@Progi1984 Progi1984 removed the Stale label Nov 18, 2022
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

6 participants