2

I'm trying to set the background color of a text both either to a color, or to 100% transparent (whatever is easiest) but I'm struggling to achieve either.

I've tried "bgColor" as per some other elements but no luck :(

 $textbox = $section->addTextBox(
        array(
            'marginTop' => -100,
            'marginLeft' => -100,
            'posHorizontal' => 'absolute',
            'posVertical' => 'absolute',
            'align' => 'left',
            'positioning' => 'relative',
            'width'       => 200,
            'height'      => 40,
            'borderColor' => '#eeeeee',
            'borderSize'  => 0,
            'bgColor' => 'black',
        )
    );
AdrianGW
  • 143
  • 1
  • 8

4 Answers4

2

Try this

'fillColor' => 'black'

Or

'fillColor' => '#BFBFBF'

you can find all properties in PhpWord\Style\TextBox.php

Cosmo
  • 21
  • 3
0

Does anyone how to do this, also have this issue. The documentation has not been updated in years. AddTextBox doesnt exist on docs...

'fill'      => array('color' => '#990000'),
'bgColor'      => '#990000',
'backgroundColor'      => '#990000'

None of the above work.

  • 1
    Any idea did you find a solution ? Another question did Text box support border radius/ round ? – famas23 Mar 23 '21 at 14:28
0

For anyone looking for this answer here it goes:

There's no answer, textbox don't support any kind of background yet and looks like it wont. As this issue suggests you can achieve the same results in terms of design with a table with a single cell.

Felipe Chagas
  • 441
  • 1
  • 6
  • 19
  • does it support border radius/ round ? – famas23 Mar 23 '21 at 14:26
  • @famas23 I'm not sure, maybe not. I gave a quick look in the code and looks like it receives just size and color for borders. See: https://github.com/PHPOffice/PHPWord/blob/develop/src/PhpWord/Style/TextBox.php – Felipe Chagas Mar 23 '21 at 15:39
0

You will need to install the latest version composer require phpoffice/phpword:dev-master to get access to bgColor property as it's not included in 1.0.

Mr Seche
  • 43
  • 9