Forum


Replies: 8   Views: 4003
Importstyles issues
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  · 19-11-2015 - 16:39

Hello,

You must run the parseStyles method standalone. This method generates a document in which you can read the available style names.

When you run standalone the method parseStyles for your DOCX that has the styles you want to import and you open the DOCX output, do you see the 'title' style name?

And why are you parsing and importing different DOCX?

$path = $this->container->getParameter('kernel.root_dir') . '/../web/bundles/rffconcertationsrest/templates/report.docx';
        $docx->parseStyles($path);

...

$docx->importStyles($this->templatePath,...

The steps you need to do are:

1. Run a standalone script in which you use the parseStyles method to generate a DOCX in which you can read the available styles. You don't use this method anymore.

2. In your script you import the styles using the importStyles method and being sure that the style name you set is exactly the same as the one you can read in the DOCX generated in the previous step.

From your script:

 array(
            'title',
...);

$docx->addText($title, array('pStyle' => 'title'));

If the style 'title' doesn't exist exactly with that name in the DOCX you're importing using the importStyles method it won't be added.

Please send to contact[at]phpdocx.com the DOCX that include the styles you want to import and we'll send you a simple script to show you how it works.

Regards.