Forum


Replies: 4   Views: 1362
Importstyles issue
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 pwctechnicalsecurity  · 29-03-2021 - 11:28

Hi,

I am encountering an issue with the importStyles function:

ErrorException

Undefined variable $name

Classes/Phpdocx/Create/CreateDocx.php:7196

I am following the simple example as outlined on https://www.phpdocx.com/api-documentation/layout-and-general/import-styles-from-a-Word-document-with-PHP.

The source DocX holds the paragraph styles: MatrixBullet, MatrixIndicator and MatrixTitle - parseStyles showed that both the ID and name are identical. I have tried both:

$docx->importStyles(app_path('Segments/_Default/Matrix/Matrix.docx'), 'merge', array('pStyle' => 'MatrixBullet'));

as well as:

$docx->importStyles(app_path('Segments/_Default/Matrix/Matrix.docx'), 'merge', array('MatrixBullet'));

 Both result in the abovementioned error.

Any suggestions?

Posted by pwctechnicalsecurity  · 29-03-2021 - 11:30

PS: using the namespace, premium version of PHPDocX 11.

Posted by admin  · 29-03-2021 - 11:52

Hello,

Please apply the following minor change and try again:

  1. Edit Classes/Phpdocx/Create/CreateDocx.php and go to that line (7196).
  2. Add the following code:
if (!isset($name)) {
  $name = 'nl' . $listId;
}

before line 7196.

This is the code to be used after applying the previous change:

$listStyleXML = str_replace('<w:abstractNum w:abstractNumId="0"', '<w:abstractNum w:abstractNumId="' . $originalAbstractNumId . '"', $listStyleXML);
if (!isset($name)) {
  $name = 'nl' . $listId;
}
self::$customLists[$name]['id'] = $listId;
self::$customLists[$name]['wordML'] = $listStyleXML;

It seems you are trying to import a custom paragraph style with a numbering style and $name is not being initializated, so you are getting that PHP notice. The previous code generates a random one when $name is not set. We have moved the post to the dev team to consider including this same change.

Regards.

Posted by pwctechnicalsecurity  · 29-03-2021 - 12:50

Works. Thanks!

Posted by admin  · 12-04-2021 - 17:52

Hello,

All phpdocx 11 packages have been updated with the same change.

Regards.