Replies: 2   Views: 757
Having issue to convert html to docx using createdocx class
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 turnercmt  · 21-11-2020 - 04:39

We are using PHPDOCX library to convert html to docx file.
To convert html to docx have used 'CreateDocx' class of PHPDOCX library.
And creating docx and downloading it using 'createDocxAndDownload' method of class.

Currently facing the issue is,

1. if html in <div>,<p>,<span> structure then while conversion into docx width of div not getting consider. So all the content showing one by one.
It's not look good specially in header and footer.

2. If we use <table> structure then while conversion into docx alignment shows proper on office 07, 13. But it's look messy on office 365. Also in Onlyoffice shows table border.

Please suggest the which method we have to call to convert the HTML to DOCX which will open in all client and keep same structure.

Posted by admin  · 21-11-2020 - 07:48


We recommend you to read the available documentation about HTML to DOCX:

For example, about div tags as explained in the previous pages:

div: Although this tag is probably the most frequent in modern HTML code, it does not have a direct translation into Word. phpdocx offers different parsing options:
Only use it for the CSS inheritance and parse consequently its child elements.
Parse them as a "p" element with the option "parseDivs" set to "paragraph" (this may be an useful option when using HTML code coming from a WYSIWYG editor).
Parse it as a table with the option "parseDivs" set to "table". This may be the most accurate option if one may decide to preserve all available formatting but may produce complicated Word documents that may be later difficult to edit manually (if that is an interesting option).

And about tables:

Defining widths in tables
In order to correctly assign widths to tables' columns it is advisable to define the width of the table as well as its cells.

If you don't set widths to tables (table an td tags), you set automatic values that are readed correctly by MS Word but not other DOCX readers, so it's recommended applying widths to tables when adding them.

phpdocx includes options and support contents/styles to get the same output in all DOCX readers and return the best transformation and output. To understand how to use the library properly, we recommend you to read the available documentation.


Posted by turnercmt  · 21-11-2020 - 13:02

Thnsk for your reply, we will check the suggested options and get back to you.