Forum


Replies: 3   Views: 86
Parsestyles returns a php notice

Posted by pwctechnicalsecurity  · 30-07-2019 - 19:32

Edited by admin · 31-07-2019 - 06:25
$docx = new CreateDocx();

$docx->parseStyles();

$docx->createDocx('output');

parseStyles is providing me with a "Notice: Undefined index: textProperties" error. Any suggestions? I have tried multiple things; like including using $docx = new CreateDocxFromTemplate('test.docx'). In all scenario's parseStyles throws the error:

(1/1) ErrorException

Notice: Undefined index: textProperties

in CreateTable.php line 598

at CreateTable->generateP('Title A', array('tableStyle' => 'TableNormal', 'columnWidths' => array(1800, 1800, 1800), 'size_col' =>array(1800, 1800, 1800), 'TBLSTYLEval' => 'TableNormal'))in CreateTable.php line 336

at CreateTable->createTable(array(array('Title A', 'Title B', 'Title C'), array('First row A', 'First row B', 'First row C'), array('Second row A', 'Second row B', 'Second row C')), array('tableStyle' => 'TableNormal', 'columnWidths' => array(1800, 1800, 1800), 'size_col' => array(1800, 1800, 1800), 'TBLSTYLEval' => 'TableNormal'), array())in CreateDocx.php line 3853

at CreateDocx->addTable(array(array('Title A', 'Title B', 'Title C'), array('First row A', 'First row B', 'First row C'), array('Second row A', 'Second row B', 'Second row C')), array('tableStyle' => 'TableNormal', 'columnWidths' => array(1800, 1800, 1800), 'size_col' => array(1800, 1800, 1800), 'TBLSTYLEval' => 'TableNormal'))in CreateDocx.php line 6836

at CreateDocx->parseStyles()in TestController.php line 41

Any clues? Thanks.

Posted by pwctechnicalsecurity  · 30-07-2019 - 20:33

PS: I am using Symfony4. The example in examples/LayoutAndGeneral/parseStyles/samples_3.php seems to be working. This is the actual code in my controller.

use Phpdocx\Create\CreateDocx;

 

/**
 * @Route("/parse")
 */
public function parse()
{
    $url = $this->getParameter('kernel.project_dir') . '/public/examples/stylesTemplate.docx';

    $docx = new CreateDocx($url);

    $docx->parseStyles();

    $docx->createDocx('parse.docx');
}

Posted by admin  · 31-07-2019 - 06:24

Hello,

The method is returning a PHP notice, not an error. It seems you are using a Symfony configuration that returns an Exception when a notice is found.

You can hide the notice using this line:

@$docx->parseStyles()

Or you can update the CreateTable.php file. In the generateP method you can use the following code:

protected function generateP($value = null, $options = null)
{
    if (!is_array($options)) {
        $options = array();
    }
    if (!isset($options['textProperties'])) {
        $options['textProperties'] = array();
    }
    
    $xmlWF = new WordFragment();
    $xmlWF->addText($value, $options['textProperties']);
    $xml = (string) $xmlWF;
    $this->_xml = str_replace('__GENERATETC__', $xml, $this->_xml);
}

This change to remove the PHP notice will be included in the next release of phpdocx.

Regards.

Posted by pwctechnicalsecurity  · 02-08-2019 - 07:04

Makes sense. Thanks.

Looking forward to your next release :-)