Forum


Replies: 6   Views: 3375
Style import
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 jean-sylvain  · 19-04-2012 - 15:51


Hi,

I try to import the styles from a docx file.
I use importStyles to get them and when I use AddText the style is not applied.
Here is the code :


$docx = new CreateDocx();

$fichier_template = "../" . DOSSIER_BROCHURE . "/plaquette.docx";

echo "<p>Ajout du fichier $fichier_template</p>";
$docx->importStyles($fichier_template, "merge", array("Titre 1", "Titre 2", "Titre 3", "Titre 4", "Titre 5", "Titre 6", "Titre 7", "Titre 8", "Titre 9"));
$docx->addDocX($fichier_template);


$paramsText = array(

'font' => 'Arial'
);

$text = "Hello World!";
$docx->addText($text, array("pStyle" => "Titre 5"));


$docx->createDocx("../" . DOSSIER_BROCHURE . "/brochure_enseignement_" . annee_scolaire_intitule($annee_scolaire));

Can you help me?

thanks

Posted by nicolas  · 11-04-2013 - 12:13

Have you tried to parse styles of your external document with this function: http://www.phpdocx.com/documentation/api-documentation/parsestyles-generates-a-word-document-with-the-available-word-styles-on-it

In my case, I tried to parse styles of a french document; the parseStyles() function found all my styles by it were not applied on the generated document...
I think you have the same problem that mine and it's a bug of the function.

Share your results please.

Regards,

Posted by jean-sylvain  · 11-04-2013 - 12:13


Thanks for your help.

When do I use the parseStyles function. Before or after the addDocx instruction?

Best regards

Posted by jean-sylvain  · 11-04-2013 - 12:13


IN fact I tried parseStyles and it doesn'to work at all.
None of my styles are imported.

Can an admin help us?

Thanks

Posted by nicolas  · 11-04-2013 - 12:13

Create a new PHP file with this code and open the DOCX generated:


[code]require_once 'classes/CreateDocx.inc';

$docx = new CreateDocx();

$docx->parseStyles(“../” . DOSSIER_BROCHURE . “/plaquette.docx”; );

$docx->createDocx('styles_trouve');[/code]

Posted by admin  · 11-04-2013 - 12:13

have you checked the example provided: http://www.phpdocx.com/showCode.php?dir=easy&file=importWordStyles.php

I think the problem comes from the fact that you have to introduce the id and not the name in the importStyles method (check the code that is given with parseStyles)....we have used the name and not the id from the impotation because is the one shown in the Word interface.....although we recognise that the process is a little convoluted :-)

If you continue to have an error importing the styles...could you please send the corresponding Word file and script to contact?