Forum


Replies: 1   Views: 541
Inset image into specific cell in a table.
Topic closed:
Please note this is an old forum thread. Information in this post may be out-to-date and/or erroneous.
Every phpdocx version includes new features and improvements. Previously unsupported features may have been added to newer releases, or past issues may have been corrected.
We encourage you to download the current phpdocx version and check the Documentation available.

Posted by TazioTom  · 21-05-2021 - 09:12

Hi, 

Is it possible to insert an image into a specific cell in a table in a word template? 

Alternatively, is it possible to dynamically change the background colour of a specific cell in a table in a word template? 

Many thanks in advance,

Tom

Posted by admin  · 21-05-2021 - 09:35

Hello,

If the cell contains a placeholder, you can create a WordFragment with an image and replace the placeholder by the new WordFragment using replaceVariableByWordFragment.
Otherwise, if there's no placeholder to be replaced, you can use insertWordFragment from DOCXPath to insert a WordFragment to any specific position in a document, such as in a cell.
In the package and the API documentation pages you can find samples about how to use both methods.

About changing a background color of a specific cell, if you are creating the table dynamically you can set cell backgroud colors using addTable or embedHTML. But if you need to change the background color of a cell in an existing table in a template you need to use customizeWordContents from DOCXCustomizer, but it's only available in Premium licenses.

Regards.