HTML Reader from PHPWord does't work with tables?

前端 未结 3 1516
抹茶落季
抹茶落季 2021-01-05 22:05

When I use Html reader for my html for converting into docx, reader is cut off my table.

PHP example:

$reader = IOFactory::createReader(\'HTML\');
$p         


        
3条回答
  •  臣服心动
    2021-01-05 22:21

    This answer is a comment of this Aviran Post : https://stackoverflow.com/a/40600565/6635967 (I don't have enought reputation to comment).

    I tried his method and I had this error :

    Attempted to call an undefined method named "addText" of class "PhpOffice\PhpWord\Element\Table". 
    

    To fix this, I had to modified the parseText function like this :

        private static function parseText($node, $element, &$styles)
    {
        $elementStyles = self::parseInlineStyle($node, $styles['font']);
    
        $textStyles = self::getInheritedTextStyles();
        $paragraphStyles = self::getInheritedParagraphStyles();
    
        // Commented as source of bug #257. `method_exists` doesn't seems to work properly in this case.
        // @todo Find better error checking for this one
        if (method_exists($element, 'addText')  || $element instanceof Cell ) {
            $element->addText($node->nodeValue, $textStyles, $paragraphStyles);
        }
    
        return null;
    }
    

    It's not a good bug fix but it's works very well for me.

提交回复
热议问题