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

Setting style forcelluly of existing element breaks the document #1423

Open
captixn opened this issue Jul 12, 2018 · 2 comments
Open

Setting style forcelluly of existing element breaks the document #1423

captixn opened this issue Jul 12, 2018 · 2 comments

Comments

@captixn
Copy link

captixn commented Jul 12, 2018

This is rather a feature request. Looking at the documentation, i have been unable to find how to either change the style of an element already created, or delete it to replace it, which creates difficulties in updating existing document rather than creating them from scratch. Forcefully editing the style breaks the document.

Expected Behavior

Locally, i added in \phpoffice\phpword\src\PhpWord\Element\Cell.php :

        public function setStyle($style){
          $this->style = $this->setNewStyle(new CellStyle(), $style, true);
        }

And call it from an object. I expect the function to set the style when I passe an array such as

    $cellStyle = array(
      'borderColor' => '#ffffff'
    );
    $_cells = $_row->getCells();
    foreach($_cells as $_cell){
      $_cell->setStyle([$cellStyle]);
    }

Current Behavior

There seems to be no public methods to set the style of existing elements, nor there is any to delete elements of containers. I'm looking for advices as how to develop these new features. Bellow details of the unexpected result of the code :

Failure Information

None errors are raised, however the document (.docx) written is broken at the location of the table whose cell styles were edited.

word_without_border_broken

The last page is not displayed.

Without calling the custom made setStyle function:
word_with_border

How to Reproduce

Add the above code to the Cell class and call it. Save the written document under .docx.

Context

  • PHP version: 7.1.8
  • PHPWord version: 0.14
@fcaraballo
Copy link

fcaraballo commented Dec 12, 2018

Same here

#882 (comment)

Looks like this is a common issue...

@FrancMunoz
Copy link

It worked for me... in PHPWord version 0.17 running PHP 7.4.1 I've also created setWidth() setter.

    public function __construct($width = null, $style = null)
    {
        $this->setWidth($width);
        $this->setStyle($style);
    }

    public function setStyle($style)
    {
        $this->style = $this->setNewStyle(new CellStyle(), $style, true);
    }

    public function setWidth($width) {
        $this->width = $width;
    }

I only modified background color on style so maybe one style is causing the problem... @captixn could you tell me which styles were you setting? I'm creating a new document but need to create all table cells before... It seems you are loading a document, isn't it?

Thank you!

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

3 participants