PHPWord icon indicating copy to clipboard operation
PHPWord copied to clipboard

setValue-> blank space at end of string gets stripped

Open pipeMore opened this issue 9 years ago • 7 comments

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 avatar Oct 15 '15 14:10 pipeMore

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

stepdi avatar Jan 24 '17 15:01 stepdi

It's not working

zlatevbg avatar Apr 04 '17 10:04 zlatevbg

Could you please send me your PHP-file and Word template? I have just checked out my example and it worked for me.

2017-04-04 13:38 GMT+03:00 Dimitar Zlatev [email protected]:

It's not working

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/PHPOffice/PHPWord/issues/637#issuecomment-291462009, or mute the thread https://github.com/notifications/unsubscribe-auth/AChVgkq3Hyl_H0ix8XMaTI7gaHQJ7SP7ks5rsh2ngaJpZM4GPf_- .

-- С уважением,

Дмитрий Степанов +7 903 190-50-28

stepdi avatar Apr 04 '17 14:04 stepdi

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

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

zlatevbg avatar Apr 04 '17 14:04 zlatevbg

anybody found solution of it?

iqbalmalik89 avatar Mar 29 '18 08:03 iqbalmalik89

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'

zlatevbg avatar Mar 29 '18 08:03 zlatevbg

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

whitespaces

ash108drush avatar Dec 12 '23 09:12 ash108drush