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

Cannot set table width through a style defined by addTableStyle() #629

Open
anrikun opened this issue Oct 8, 2015 · 9 comments
Open

Cannot set table width through a style defined by addTableStyle() #629

anrikun opened this issue Oct 8, 2015 · 9 comments

Comments

@anrikun
Copy link
Contributor

anrikun commented Oct 8, 2015

According to documentation this should write a 100% width table but width is ignored:

    $table_style = array(
      'unit' => \PhpOffice\PhpWord\Style\Table::WIDTH_PERCENT,
      'width' => 100 * 50,
    );
    $php_word->addTableStyle('myTable', $table_style);
    $table = $section->addTable('myTable');

Only the following writes a 100% width table as expected:

    $table = $section->addTable(array(
      'unit' => \PhpOffice\PhpWord\Style\Table::WIDTH_PERCENT,
      'width' => 100 * 50,
    ));

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

@anrikun anrikun changed the title TableStyle's width is ignored when writing docx Cannot set table width through a style defined by addTableStyle() Oct 8, 2015
@B-Prod
Copy link

B-Prod commented Feb 3, 2017

I can confirm this with the last version of PHPWord.

@tanc
Copy link

tanc commented Mar 15, 2017

Also confirmed.

@ant-s
Copy link

ant-s commented Mar 30, 2017

Yes, this is the case. I'm not sure why you also need 100 * 50 for the width. It's possible that if the width is just set to a really large number then it just takes up 100%.

Edit: I just saw the comment:
// Width in fiftieths (1/50) of a percent (1% = 50 unit)
Seems to be a word thing.

@ant-s
Copy link

ant-s commented Mar 30, 2017

The table style class works well for setting items like so:

    // Create a new table style
    $table_style = new \PhpOffice\PhpWord\Style\Table;
    $table_style->setBorderColor('cccccc');
    $table_style->setBorderSize(1);
    $table_style->setUnit(\PhpOffice\PhpWord\Style\Table::WIDTH_PERCENT);
    $table_style->setWidth(100 * 50);

    // Add a section to the document.
    $section = $this->phpword->addSection();

    // Set up our table.
    $table = $section->addTable($table_style);

There's a setStyleName on a parent class which just sets $this->styleName, and I'm not sure if there's a way to subsequently refer to the style by name.

@newbro
Copy link

newbro commented Aug 10, 2017

Just hit this bug as well.

@rebekahocampo
Copy link

Does anyone know the status of this bug? I just installed phpoffice/phpword a couple days ago, and while developing my code, I noticed this same thing is happening. Very Confusing. Thanks @ant-s for the alternative.

@joaodos3v
Copy link

Thanks @ant-s , your answer resolved my issue:

I was having trouble uploading a file I had generated with phpword that contained a table. By uploading this and using the storeAs method, the table lost its edges.

Now it work.

@icy2003
Copy link

icy2003 commented Apr 23, 2019

me too……on "phpoffice/phpword": "^0.16.0" (composer.json)

@chrisribe
Copy link

Same issue, trying to use a style defined in my document template example "TBL1" but also specify the table width which must be set per table. Seems it is not part of the style in MsWord.

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

9 participants