Forum


Replies: 3   Views: 338
Embedhtml sets both cell shading and text highlight
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 admin  · 23-05-2025 - 09:25

Hello,

The easiest approach with phpdocx 16 to accomplish the requested task is to apply a transparent background to the cell contents. Please note that you need to wrap the text contents in tags (such as p or span ) to apply styles to the contents.

For example:

$html = '
<style>
    td {
        background-color: yellow;
    }
    td p, td span {
        background-color: transparent;
    }
</style>
<table border="1" style="border-collapse: collapse" width="500">
    <tbody>
        <tr>
            <td width="400"><p>1_1</p></td>
            <td width="400"><p>1_2</p></td>
        </tr>
        <tr>
            <td><span>2_1</span></td>
            <td><span>2_2</span></td>
        </tr>
    </tbody>
</table>';
$docx->embedHTML($html);

This same approach may work with some previous phpdocx versions.

Regards.