Replies: 2   Views: 1568
Import external stylesheet file
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  · 04-11-2019 - 07:27


We recommend you to check the examples available on You can apply CSS styles using style tags:

        p {font-style: italic;}
        p.header {font-size: 20px; font-weight: bold;}
        div.footer {font-size: 10px;}

external CSS files:

<link href="styles.css" type="text/css" rel="stylesheet" />

and inline styles:

    <td style="background-color: #ffff00">Cell 1 1</td>
    <td>Cell 1 2</td>

CSS styles must be applied each time embedHTML or replaceVariableByHTML are called.

UPDATE: HTML Extended ( , available in Premium licenses, includes addBaseCSS to set a base CSS used for all HTML conversions in the same script.


Posted by jhanley  · 04-11-2019 - 22:59

Right, I'm already prepending a string containing inline style classes. Example:

$style = "<style>
p, span[style] {
  font-family: Arial;
  font-size: 7.5pt;

I just thought phpdocx might provide a method for loading external stylesheets.

That said, I will simply roll my own solution for loading an external text file. Thanks.