PHPOffice/PHPWord · error · Exception

The part " " doesn't exist

Error message

The part "%s" doesn't exist

What it means

Word2007's readPart maps an OOXML part name to a reader class PhpOffice\PhpWord\Reader\Word2007\{partName}. If that class does not exist, the document references a part the reader cannot handle, so it throws.

Solutions

  1. Update PhpWord to the latest version for additional part support
  2. Open the .docx (rename to .zip) and inspect word/_rels/document.xml.rels for unusual parts
  3. Re-save the document in Microsoft Word or LibreOffice to normalize parts
  4. Remove or ignore the offending custom part if it is not needed

Example fix

// before
$phpWord = \PhpOffice\PhpWord\IOFactory::load('thirdparty.docx'); // unsupported part
// after
try {
    $phpWord = \PhpOffice\PhpWord\IOFactory::load('thirdparty.docx');
} catch (\Exception $e) {
    // resave via LibreOffice to normalize parts
    shell_exec('libreoffice --headless --convert-to docx thirdparty.docx');
    $phpWord = \PhpOffice\PhpWord\IOFactory::load('thirdparty_converted.docx');
}
Defensive patterns

Strategy: try-catch

Validate before calling

$zip = new \ZipArchive(); if ($zip->open($docFile) === true) { $rels = $zip->getFromName('word/_rels/document.xml.rels'); $zip->close(); } // inspect for unusual part names

Try / catch

try { $phpWord = \PhpOffice\PhpWord\IOFactory::load($docFile); } catch (\PhpOffice\PhpWord\Exception\Exception $e) { if (str_contains($e->getMessage(), 'doesn\'t exist')) { // resave doc in Word/LibreOffice to normalize } throw $e; }

Prevention

When it happens

Trigger: Loading a .docx whose document.xml.rels references a part with no corresponding reader class (rare/unsupported part types, corrupted relationship data, or documents produced by non-Word generators with unusual part names).

Common situations: Third-party docx generators emitting custom parts; corrupted or hand-edited .docx packages; PhpWord version lacking a newly added part reader.

Related errors


AI-assisted analysis of PHPOffice/PHPWord@aef95c0415 (2026-09-14). Data as JSON: /api/errors/c89f797b2b10c4ed. Report an issue: GitHub.

Appendix: source

Thrown at src/PhpWord/Reader/Word2007.php:108

                    $part = $this->readPart($phpWord, $relationships, $commentRefs, $partName, $docFile, $xmlFile);
                    $commentRefs = $part->getCommentReferences();
                }
            }
        }

        return $phpWord;
    }

    /**
     * Read document part.
     *
     * @param array<string, array<string, null|AbstractElement>> $commentRefs
     */
    private function readPart(PhpWord $phpWord, array $relationships, array $commentRefs, string $partName, string $docFile, string $xmlFile): AbstractPart
    {
        $partClass = "PhpOffice\\PhpWord\\Reader\\Word2007\\{$partName}";
        if (!class_exists($partClass)) {
            throw new Exception(sprintf('The part "%s" doesn\'t exist', $partClass));
        }

        /** @var AbstractPart $part Type hint */
        $part = new $partClass($docFile, $xmlFile);
        $part->setImageLoading($this->hasImageLoading());
        $part->setRels($relationships);
        $part->setCommentReferences($commentRefs);
        $part->read($phpWord);

        return $part;
    }

    /**
     * Read all relationship files.
     *
     * @param string $docFile
     *
     * @return array

View on GitHub (pinned to aef95c0415)