Forum


Replies: 2   Views: 1606
Crash - undefined index: border_top_width
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 vpratfr  · 05-07-2020 - 11:25

Hi,

We use your library to convert HTML to Word documents. On some documents, we see the error :

ErrorException {#159166
  #message: "Undefined index: border_top_width"
  #code: 0
  #file: "/home/vagrant/code/packages/phpdocx/Classes/Phpdocx/Transform/HTML2WordML.php"
  #line: 2197
  #severity: E_NOTICE
  trace: {
    /home/vagrant/code/packages/phpdocx/Classes/Phpdocx/Transform/HTML2WordML.php:2197 {
      Phpdocx\Transform\HTML2WordML->generateTblPr($properties, $attributes)
      › foreach (self::$borders as $key => $value) {
      ›     if (isset($properties['border_' . $value . '_style']) && $properties['border_' . $value . '_color'] != 'none' && $properties['border_' . $value . '_width'] != null) {
      ›         $stringTblPr .= '<w:' . $value . ' w:val="' . $this->getBorderStyles($properties['border_' . $value . '_style']) . '"  w:color="' . $this->wordMLColor($properties['border_' . $value . '_color']) . '" w:sz="' . $this->wordMLLineWidth(isset($properties['border_' . $value . '_width']) ? $properties['border_' . $value . '_width'] : '') . '" />';
    }
    /home/vagrant/code/packages/phpdocx/Classes/Phpdocx/Transform/HTML2WordML.php:975 { …}
    /home/vagrant/code/packages/phpdocx/Classes/Phpdocx/Transform/HTML2WordML.php:1622 { …}

Do you have any hint? I can send the HTML code to a confidential email if needed.

Here is how we create the document:

$docx = new CreateDocx();
$docx->embedHTML(file_get_contents($htmlFile));
$docx->removeHeadersAndFooters();
$docx->createDocx($wordFile);

Regards,

Posted by admin  · 05-07-2020 - 12:11

Hello,

It's not returning a PHP error but a PHP notice that you can hide if needed (https://www.php.net/manual/es/function.error-reporting.php), or directly using:

@$docx->embedHTML(file_get_contents($htmlFile));

If you don't want to hide PHP notices, please set a border width value for the table you are adding when importing HTML. We have sent this topic to the dev team to check the PHP notice.

Regards.

Posted by vpratfr  · 06-07-2020 - 09:29

Thanks, I'll check my stylesheet, I don't want to ignore PHP warnings.

Your code reads

// file: "./packages/phpdocx/Classes/Phpdocx/Transform/HTML2WordML.php"
// line: 2198

if (isset($properties['border_' . $value . '_style']) 
    && $properties['border_' . $value . '_color'] != 'none' 
    && $properties['border_' . $value . '_width'] != null)

It would be safe to add a `isset($properties['border_' . $value . '_width']) ` to get rid of that warning. Additionally, there should be a default width set anyway by the Docx creator.

// file: "./packages/phpdocx/Classes/Phpdocx/Transform/HTML2WordML.php"
// line: 2198

if (isset($properties['border_' . $value . '_style']) 
    && isset($properties['border_' . $value . '_color']) 
    && isset($properties['border_' . $value . '_width']) 
    && $properties['border_' . $value . '_color'] != 'none' 
    && $properties['border_' . $value . '_width'] != null)