Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Section exists for PHPWord Reader, not for Word2007 Writer (only Container present) #2466

Open
thomasb88 opened this issue Sep 11, 2023 · 0 comments

Comments

@thomasb88
Copy link

Describe the Bug

Using TemplateProcessor, setComplexBlock, trying to add a section. But no section existing in PhpOffice\PhpWord\Writer\Word2007\Element\ result in PHP error

public function setComplexBlock($search, Element\AbstractElement $complexType): void
{
$elementName = substr(get_class($complexType), strrpos(get_class($complexType), '\') + 1);
$objectClass = 'PhpOffice\PhpWord\Writer\Word2007\Element\' . $elementName;

    $xmlWriter = new XMLWriter();
    /** @var \PhpOffice\PhpWord\Writer\Word2007\Element\AbstractElement $elementWriter */
    $elementWriter = new $objectClass($xmlWriter, $complexType, false);
    $elementWriter->write();

    $this->replaceXmlBlock($search, $xmlWriter->getData(), 'w:p');
}

Steps to Reproduce

$section = (new PhpWord())->addSection();
OR
$objectClass = 'PhpOffice\PhpWord\Element\' . 'Section';
$word_obj = new $objectClass();

THEN
$this->setComplexBlock($search, $section, 'Variable', 1, false);

with $search the block macro (and needs a template too)

Expected Behavior

Add the section in the tempDocumentMainPart

Current Behavior

PHP Error

Context

  • PHP Version: 7.4
  • PHPWord Version: 1.1.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

1 participant