Forum


Replies: 1   Views: 18
Microsoft publisher - importing docx documents: issues with table cell content and strictwordstyles

Posted by mschill  · 01-07-2025 - 08:50

Hello,

I'm using phpdocx to generate a DOCX document from HTML that is later edited in Microsoft Publisher. Unfortunately, Publisher does not display the content of certain table cells correctly — especially when those cells contain multiple blocks or line breaks. The content sometimes disappears entirely.

To work around this, I’ve removed all <p> tags from my HTML and replaced them with <br /> and inline styles only. This helps in many cases, but not all.

I noticed that enabling strictWordStyles = true makes the document render correctly in Publisher (no missing content), but then I lose formatting options like background colors in table headers.

My questions:

  1. Is this a known issue with Publisher compatibility?

  2. Is there a way to apply strictWordStyles = trueonly to specific parts of the document, for example, only inside certain table cells?

For context, here's a simplified example of what gets generated:

Problematic output (Publisher breaks rendering):

<w:p>
  <w:pPr>
    <w:widowControl w:val="on"/>
    <w:pBdr/>
    <w:spacing w:before="105" w:after="30" w:line="379" w:lineRule="auto"/>
  </w:pPr>
  <w:r>
    <w:rPr>...</w:rPr>
    <w:t>Hl. Messe</w:t>
  </w:r>
  <w:r>
    <w:rPr>...</w:rPr>
    <w:br/>
    <w:t>nach Meinung</w:t>
  </w:r>
</w:p>

Working output in Publisher:

<w:p>
  <w:pPr>
    <w:widowControl w:val="on"/>
  </w:pPr>
  <w:r>
    <w:rPr>
      <w:b/>
    </w:rPr>
    <w:t>Hl. Messe</w:t>
  </w:r>
  <w:r>
    <w:rPr/>
    <w:br/>
    <w:t>nach Meinung</w:t>
  </w:r>
</w:p>

 

Kind regards,
Anna Krämer

Posted by admin  · 01-07-2025 - 09:37

Hello,

Please note that the strictWordStyles option does the following:

If true ignores almost all CSS styles

If you enable this option, almost all CSS styles are not applied. This option is useful when applying custom styles using the wordStyles option.
The strictWordStyles option is applied to the whole transformation. There's no option to apply this option only to specific parts of the document.

If you don't want to apply specific styles, you need to add additional CSS styles. For example, setting the border as none to not adding a border style in a table.

Regarding Microsoft Publisher, please note that it doesn't support many contents and styles available in DOCX documents: colspans, rowspans, spacings, borders, links, endnotes, comments, headers, footers... Please note that this is not a phpdocx issue, but a limitation from Microsoft Publisher that only supports simple DOCX documents.

Instead of Microsoft Publisher, we recommend you open the same DOCX with MS Word, LibreOffice, and other DOCX editors. The OOXML code you have posted is correct and valid.

Regards.