Forum


Replies: 5   Views: 450
Importcontents only for body, not for header/footer
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 admin  · 09-11-2023 - 22:23

Hello,

Please note that importContents uses MultiMerge internally using in-memory documents (https://www.phpdocx.com/documentation/cookbook/in-memory-docx-documents) to avoid generating extra files.

Using importContents, you can avoid importing specific elements using a custom XPath query. For example internal sections:

$referenceNode = array(
    'customQuery' => '//w:body/*[not(self::w:p/w:pPr/w:sectPr)]',
);

$docx->importContents('document.docx', $referenceNode);

But we think the easiest approach would be importing all contents to the DOCX and then use importHeadersAndFooters (https://www.phpdocx.com/api-documentation/layout-and-general/import-headers-and-footers-Word-document-with-PHP) to set headers and footers as the first DOCX.

If the contents to be imported doesn't include external relationships (such as images or charts), an alternative approach can be done getting the XML of the contents with getDocxPathQuery (https://www.phpdocx.com/api-documentation/docx-path/get-docx-path-query-info) and adding them using addWordML (https://www.phpdocx.com/api-documentation/word-content/add-raw-wordml-Word-document).

If you send to contact[at]phpdocx.com two or three sample DOCX documents we'll check them to generate a custom script.

Regards.