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

setValue-> blank space at end of string gets stripped #637

Open
pipeMore opened this issue Oct 15, 2015 · 7 comments
Open

setValue-> blank space at end of string gets stripped #637

pipeMore opened this issue Oct 15, 2015 · 7 comments

Comments

@pipeMore
Copy link

pipeMore commented Oct 15, 2015

Hi,

I'm currently bound to version 0.6.2.
Working with my Template-docx, I'm replacing values successfully via setValue(), BUT:
When I try to add a comma followed by a blank space as string (', '), the blank space always gets stripped if being at the end of a string. That's really annoying, because I need that space, I cant set it fix in the Template, because it's in a variable position.

Bug ? Feature ? Ideas to fix this problem ?

I'm not doing things like rtrim before setValue, so this seems to be a problem of PHPWord (0.6.2).


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

@pipeMore pipeMore changed the title setValue strips blank space at end of string setValue-> blank space at end of string gets stripped Oct 15, 2015
@stepdi
Copy link

stepdi commented Jan 24, 2017

try this:
$templateProcessor->setValue('UPPER', '<w:t xml:space="preserve"> 0</w:t>');

@zlatevbg
Copy link

zlatevbg commented Apr 4, 2017

It's not working

@stepdi
Copy link

stepdi commented Apr 4, 2017 via email

@zlatevbg
Copy link

zlatevbg commented Apr 4, 2017

Sorry, in my case it doesn't work because I have Output Escaping turned on:

\PhpOffice\PhpWord\Settings::setOutputEscapingEnabled(true);

@iqbalmalik89
Copy link

anybody found solution of it?

@zlatevbg
Copy link

In my case I'm overriding the following method:

protected function setValueForPart($search, $replace, $documentPartXML, $limit)
{
    $replace = preg_replace('/\\\n/', '<w:br/>', $replace); // replace \n with 'newline'
    $replace = preg_replace('/\\\s/', '<w:t xml:space="preserve"> </w:t>', $replace); // replace \s with 'space'
        
    return parent::setValueForPart($search, $replace, $documentPartXML, $limit);
}

In my language strings I use \n and \s instead of 'newline character' and 'space'

@ash108drush
Copy link

ash108drush commented Dec 12, 2023

$replace = preg_replace("/\\\s/", '<w:t xml:space="preserve">&#160;</w:t>', $replace);

whitespaces

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

5 participants