API Documentation
Word content
Format conversion
CryptoPHPDOCX
Digital Signature package
importStyles
imports Word styles from an external Word document
PRO, PRO+ and CORPORATE PHPDocX >= 2.5
Description
public importStyles (string $path, string $type [, array $myStyles= array() [, string $styleIdentifier]])
This method allows for the import of Word styles from an external Word document.
You may replace the whole stylesheet or just import a certain list of predefined styles.
If you need to know which styles are available for importation from an external Word document you may use the parseStyles method.
Parameters
path
The path to the Word document from which we want to import the styles.
type
The available options are:
- ‘replace’ if you wish to overwrite the whole stylesheet or
- ‘merge’ if you only want to import the styles listed in the $myStyles array.
myStyles
An array with all the names of the styles that you wish to import. You may use the parseStyles($path) method to discover which styles are available.
styleIdentifier
The posible values are:
- ’styleName’ (default value) if you wish to identify the styles included in $myStyles array by their name or
- ’styleID’ if you want to use their id.
You may get the names and/or ids of the styles with the help of the parseStyles method.
Return values
Void.
Code samples
Example #1: imports a single style from an external Word document
require_once 'classes/CreateDocx.inc';
$docx = new CreateDocx();
//You may first check the available styles using the parseStyles('../files/TemplateStyles.docx') methohd
$docx->importStyles('../files/TemplateStyles.docx', 'merge', array('crazyStyle'));
$docx->addText('This is the resulting paragraph with the "CrazyStyle".', array('pStyle' => 'crazyStyle'));
//You may also import a complete XML style sheet by
//$docx->importStyles('../files/TemplateStyles.docx', $type= 'replace');
$docx->createDocx('example_import_word_styles');
The resulting Word document looks like (download .docx file):
Change log
- Available since 2.5
- The parameter styleIdentifier is available since 3.1
Available examples
See also
PHPDocx. Dinamic generation of reports in .docx format 


