Forum


Replies: 3   Views: 1451
Upgrade to v10 break my style
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 nschrevel  · 02-07-2020 - 11:49

Hello,

After upgrading to v10, i loose my Word Style, they are now in English in my Word : Heading 1, Heading 2, Heading 3 ... I loose automatic number (like 1.1.1 for H3, 1.1 for H2 etc...).

example

To convert, i'm using a template.docx with all my style (Titre 1, Titre 2 with numbering) and header (image with title). I loose my image and header too.

May be there is an upgrade guide ?

Thanks

Nicolas

Posted by admin  · 02-07-2020 - 12:00

Hello,

phpdocx 10 is fully compatible with the API of previous versions (the API is the same but adding new options, classes and methods). It doesn't have changed anything related to how MS Word styles are handled; maybe you need to enable some option?

phpdocx doesn't remove contents or styles from a template unless specific methods are used.

Please send to contact[at]phpdocx.com the most simple script (and the template) that illustrates your issue, the version number you were using before phpdocx 10 and both DOCX outputs (using phpdocx 10 and the other phpdocx version).

Regards.

Posted by nschrevel  · 02-07-2020 - 12:21

it was a v7.

 

i'll send you files & code.

Posted by admin  · 02-07-2020 - 12:52

Hello,

Thanks for sending the template and the code you are using. The problem is that you are using the following line:

$docx = new CreateDocx('../web/template/template.docx');

and to load a template you need to use

$docx = new CreateDocxFromTemplate('../web/template/template.docx');

This way of loading the template is the recommended one from phpdocx 4 (you can check the included samples in phpdocx 7 too). The first option of CreateDocx:

/**
     * Constructor
     *
     * @access public
     * @param string $baseTemplatePath. Optional, phpdocxBaseTemplate.docx as default
     * @param $docxTemplatePath. User custom template (preserves Word content)
     */
    public function __construct($baseTemplatePath = PHPDOCX_BASE_TEMPLATE, $docxTemplatePath = '')

is only for specific base templates (to overwrite default templates in the DOCX) and should never be used but in very specific cases. Since phpdocx 4, the way to load a template is using CreateDocxFromTemplate (otherwise you can't use template methods): https://www.phpdocx.com/documentation/practical/working-with-templates

Regards.