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 Alain DIAS  · 19-11-2015 - 16:23

 

I've of course already read the API documentation in detail. Import a template seems to be a tricky part.

I tried the code below. None of my custom styles are applied. I tried to open the template file to see what is generated. But Word said to me that problems have been detected (and doesn't want to open). I suppose that is why my custom styles aren't applied (maybe).

private function generateTemplate()
    {
        // Create a new document
        $docx = new \Phpdocx();
        // Imports style from the template
        $path = $this->container->getParameter('kernel.root_dir') . '/../web/bundles/rffconcertationsrest/templates/report.docx';
        $docx->parseStyles($path);
        $uploadPath = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/';
        $this->templatePath  = $uploadPath.'templateParseStyles.docx';
        $docx->createDocx($uploadPath.'templateParseStyles');
    }

public function generate(){
$this->generateTemplate();
// Create a new document
        $docx = new \Phpdocx();
$docx->importStyles($this->templatePath, 'merge', array(
            'title',
            'subTitle',
            'subSubTitle',
            'section',
            'subSection')
        );
$docx->addText($title, array('pStyle' => 'title'));
}